![](/img/trans.png)
[英]Android - onTouchListener not working for child LinearLayout
[英]LinearLayout minHeight not working with weigth="1"
我整个下午都在尝试让minHeight
属性起作用。
我想要的是linearMe
布局:
随着 ListView 变大,我希望linearMe
布局:
我的问题是随着 ListView 中有更多元素, linearMe
布局越来越小。 而当 listView 有足够的元素填满屏幕时, linearMe
布局就消失了。 在这种情况下,看起来minHeight
没用。
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent" >
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:id="@+id/linearMe"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#FF0000"
android:minHeight="200dp" />
</LinearLayout>
我希望你能帮助我::)
也将android:layout_weight="1"
到 ListView。 将它们(list & linearMe) android:layout_height
属性更改为"match_parent"
删除`minHeight。
这样每个视图将占据屏幕的一半。`
您可能想使用“View”而不是“LinearLayout”来尝试间隔布局。 ViewGroup 类有时会稍微不同地处理布局。
如果您愿意使用ConstraintLayout
作为父容器,以下 xml 应该可以满足您的目的:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constrainedHeight="true"
app:layout_constraintBottom_toTopOf="@id/linearMe"
app:layout_constraintTop_toTopOf="parent"
tools:listitem="@android:layout/list_content" />
<LinearLayout
android:id="@+id/linearMe"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#FF0000"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/list"
app:layout_constraintHeight_min="200dp"
android:orientation="vertical"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
我所做的是我已经定义了将list
和linearMe
相互链接的约束。 app:layout_constraintHeight_min="200dp"
将确保 linearMe 的最小高度为linearMe
。 app:layout_constrainedHeight="true"
确保当list
有更多项目时,它不会隐藏在linearMe
后面。
我无法用一些数据来测试它来填充ListView
。 您可以尝试一下并在此处发布您的反馈。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.