0

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?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Soheil
  • 1,676
  • 7
  • 34
  • 65
  • Check this out: http://stackoverflow.com/questions/5731487/how-to-add-views-to-linear-layout That takes care of adding the view to your LinearLayout. – Steven Roberts Dec 29 '13 at 16:23

2 Answers2

1

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());
Orphamiel
  • 874
  • 13
  • 22
0

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