以编程方式设置 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 - 是您要使用的视图
//min Height - 你要设置的最小高度
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, minHeight);
yourView.setLayoutParams(params);
这是我的代码。
<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 - 是您要使用的视图
//min Height - 你要设置的最小高度
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, minHeight);
yourView.setLayoutParams(params);