-1

I am using a frameLayout and adding that to a viewgroup that already consists of a list view. Now the problem that arise is that the frameview is settled a bottom. I want it to come down at the bottom.

Here is my code:

public void addToView(ViewGroup view){
    view.addOnLayoutChangeListener(layoutChangeListener);

     frameParams = new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT
    );


    removeAllViews();
    View v = makeControllerView();
    view.addView(v, frameParams);
}
Rahul Verma
  • 25
  • 1
  • 8
  • Sorry this is confusing, at least to me. Do you mean it is positioned at the bottom but you only want to see it when you scroll to the bottom of the list? – zgc7009 Feb 04 '16 at 17:27
  • No by default the framelayout is positioned at the top. But I want it to stay at bottom. – Rahul Verma Feb 04 '16 at 17:30
  • This can be done by utilizing gravities or rules with a RelativeLayout parent container. – zgc7009 Feb 04 '16 at 17:31
  • How to do that. and I am using frame layout not relative layout. Kindly elaborate. – Rahul Verma Feb 04 '16 at 17:35
  • Can you post the xml file you are trying to work with so I can help modify it to fit your needs? – zgc7009 Feb 04 '16 at 17:36
  • It is useless, because the linear layout in the frame layout is fine. But the frame layout params are not giving me options to set the gravity or to set it at bottom. the issue is not with xml but the layout params – Rahul Verma Feb 04 '16 at 17:40
  • Well, you can't do it the way you are doing it. You can't use a LinearLayout to achieve what you want to achieve, at least not without modifying the contents of your xml file. That is why I am asking to see your file, so I can make an xml layout for you that will accomplish what you want. – zgc7009 Feb 04 '16 at 17:41
  • Let me rephrase the question. Can I move a particular view to the bottom of a view group. Or there are two views one is list view and the other is frame layout. I am adding the frame layout but I want it at the bottom of view group in which both of them exists. – Rahul Verma Feb 04 '16 at 17:47
  • Not in a LinearLayout like this :) At least not without a major headache in regards to measuring/laying everything out. – zgc7009 Feb 04 '16 at 17:51

1 Answers1

0

You need something like this

<RelativeLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ListView (or android.support.v7.widget.RecyclerView)
        android:id="@+id/listview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</RelativeLayout>

And then to add the view do something like

RelativeLayout container = (RelativeLayout) findViewById(R.id.container);

int vId = 1234;
View v = makeControllerView();
v.setId(vId);
RelativeLayout.LayoutParams vParams = new RelativeLayout.LayoutParams(
    RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
vParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
container.addView(v, vParams);

RelativeLayout.LayoutParams lvParams = 
        (RelativeLayout.LayoutParams) container.getLayoutParams();
lvParams.addRule(RelativeLayout.ABOVE, vId);
ListView lv = (ListView) findViewById(R.id.listview);
lv.setLayoutParams(lvParams);

I haven't tested this and have no idea if it works, but it is just to give you an idea of how it could be handled. This is not how I would handle this, if I knew there was the possibility of a view being added in this situation I would just add the view to the xml's layout and handle it's visibility. This is just since you asked.

zgc7009
  • 3,371
  • 5
  • 22
  • 34
  • okay so your advice is that play with visibility. Rather than adding views. – Rahul Verma Feb 04 '16 at 18:04
  • Yes, as you can see dynamically adding views, particularly when you are interested in their position within layouts, and even more so if dynamically sized views (like lists) are in there, the process can get overwhelming compared to something like `if(shouldShow) view.setVisibility(View.VISIBLE);` – zgc7009 Feb 04 '16 at 18:06
  • But what will I do when there are 7 activities. I want make it modular. That's why. – Rahul Verma Feb 04 '16 at 18:11
  • @RahulVerma what are the differences in the 7 activities? If they all have different views you are adding I would handle it with separate layouts, if there are only minor differences (some show a view where some don't) then you can handle it with visibilities, if they all are similar but contain a major difference, for example a different footer view, then you could create an abstract parent class activity that has an abstract method like `protected abstract View getFooterView();`, subclass it for each activity, override the method, and reply with the appropriate view. – zgc7009 Feb 04 '16 at 18:18
  • Don't know. will try it and get to you later. – Rahul Verma Feb 04 '16 at 18:20