Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android-添加一个填充屏幕高度的视图_Android_Fill Parent - Fatal编程技术网

android-添加一个填充屏幕高度的视图

android-添加一个填充屏幕高度的视图,android,fill-parent,Android,Fill Parent,我想通过编程将视图添加到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/mai

我想通过编程将
视图
添加到
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" />

我想让新视图填充屏幕高度。怎么可能呢?

试试这个:

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());

设置线性布局属性 android:layout\u width=“匹配内容” android:layout\u height=“匹配内容”

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