0

我想以编程方式添加一个View声明mainHolder如下:

<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" />

我希望新视图填充屏幕高度。这怎么可能?

4

2 回答 2

1

尝试这个 :

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());
于 2013-12-29T16:24:34.553 回答
0

设置线性布局属性 android:layout_width="match_content" android:layout_height="match_content"

然后添加以下代码: 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);

与上面的代码相同,您可以通过编程方式添加视图

于 2013-12-29T16:26:36.073 回答