【问题标题】:android - add a view which fills the screen heightandroid - 添加一个填充屏幕高度的视图
【发布时间】:2013-12-30 00:26:36
【问题描述】:

我想以编程方式将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" />

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

【问题讨论】:

标签: android fill-parent


【解决方案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());

【讨论】:

    【解决方案2】:

    设置线性布局属性 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);
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-16
      • 1970-01-01
      • 2013-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-10
      • 2010-09-10
      相关资源
      最近更新 更多