android - add a view which fills the screen height

61 views Asked by At

I want to programmatically add a View to mainHolder that is declared as below:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000" >

<LinearLayout
    android:id="@+id/mainHolder"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#000000"
    android:orientation="horizontal" />

I want the new view to fill the screen height. How is that possible?

2

There are 2 answers

0
Orphamiel On

Try this :

LinearLayout mainHolder = (LinearLayout)findViewById(R.id.mainHolder);
//untested adding of view I got it from http://stackoverflow.com/questions/5731487/how-to-add-views-to-linear-layout
mainHolder.addView(View, mainHolder);
//this is tested however
View.setMinimumHeight(mainHolder.getHeight());
0
AudioBubble On

set Linear Layout property android:layout_width="match_content" android:layout_height="match_content"

Then add following code: LinearLayout mainHolder=(LinearLayout)findViewById(R.id.mainHolder);

    RelativeLayout.LayoutParams layer=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, 
            RelativeLayout.LayoutParams.MATCH_PARENT);
    layer.addRule(RelativeLayout.ALIGN_PARENT_TOP);


    mainHolder.addView(layer);

Same as above code, you can add your views programatically