以编程方式设置LinearLayout的minHeight

San*_*ket 3 android android-layout android-linearlayout android-cardview

这是我的代码.

<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>
Run Code Online (Sandbox Code Playgroud)

我在xml中设置了线性布局的minHeight.但我想以编程方式设置它.我在这种线性布局中有两张牌.而且我想设置我的了minHeight两张牌高度的基础上.

Ami*_*ela 9

您可以使用 View.setMinimumHeight()

查看developer.android的更多细节:

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