繁体   English   中英

以编程方式设置LinearLayout的minHeight

[英]Set minHeight of LinearLayout Programmatically

这是我的代码。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:minHeight="1000dp">
<android.support.v7.widget.CardView
                    xmlns:card_view="http://schemas.android.com/apk/res-auto"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="8dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginRight="16dp"
                    card_view:cardCornerRadius="2dp"
                    card_view:cardElevation="2dp">
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
                    xmlns:card_view="http://schemas.android.com/apk/res-auto"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="8dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginRight="16dp"
                    card_view:cardCornerRadius="2dp"
                    card_view:cardElevation="2dp">
</android.support.v7.widget.CardView>
</LinearLayout>

我在xml中设置了线性布局的minHeight。 但我想以编程方式设置它。 我在这种线性布局中有两张牌。 我想根据我的两张牌高度来设置minHeight

你可以使用View.setMinimumHeight()

查看developer.android的更多细节:

http://developer.android.com/reference/android/view/View.html#setMinimumHeight(int)

// yourView - 是您要使用的视图

// minHeight - 您想要设置的最小高度

  LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, minHeight);
    yourView.setLayoutParams(params);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM