如何动态增加Android Layout中视图的高度?

时间:2016-08-01 17:00:14

标签: java android android-layout view

如何在图像中动态扩展分离的垂直线(视图)的高度?

这是我正在使用的XML:

<View android:layout_width="1dp" 
      android:layout_height="100dp" 
      android:id="@+id/view_verdict" 
      android:background="@color/line"             
      android:foregroundGravity="center_horizontal" 
      android:layout_alignParentTop="true"  
      android:layout_centerHorizontal="true" />

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:0)

也许这个示例代码很有用(我想你的视图是一个LinearLayout):

    final int newHeight = 100; //this is the new height will be set in your view
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, newHeight);//first param is the width, and second the height
    myView.setLayoutParams(params);

或者只是把:

...
android:layout_height="match_parent"
...

答案 1 :(得分:0)

设置

android:layout_height="match_parent"
标识view_verdict

的视图的