【发布时间】:2019-06-24 17:21:19
【问题描述】:
我的布局定义如下。
<ScrollView
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:id="@+id/section1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:text="@string/anomaly_products_title"
android:textColor="@color/title"
android:textSize="16sp"
android:textStyle="bold" />
<ListView
android:id="@+id/section1_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="40dp"
android:divider="@android:color/transparent"
android:dividerHeight="20dp" />
</LinearLayout>
.... Some Other section
</LinearLayout>
</ScrollView>
我还定义了列表的项目如下。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="13dp"
android:background="@drawable/semi_rounded">
<CheckBox
android:id="@+id/checkbox_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp" />
</LinearLayout>
我想将ListView 的高度设置为他所有元素的高度并使其不可滚动。滚动只能发生在父 ScrollView 上。为此,我找到了函数setListViewHeightBasedOnChildrenhere。
问题是我的复选框标签可以显示在多行上,因此会稍微增加项目的大小。在这种情况下,如果有许多复选框,ListView 就会变成可滚动的。
有没有办法处理这种情况?
【问题讨论】: