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