未解释Android ListView布局
我有一个带有自定义适配器的简单ListView。我已经用ConstraintLayout为项目布局建模。一切正常,除非某个文本视图包含长文本,使其位于第二行并与下一个文本重叠。如何使项目仅在需要时垂直展开 我的列表视图:未解释Android ListView布局,android,listview,textview,android-constraintlayout,Android,Listview,Textview,Android Constraintlayout,我有一个带有自定义适配器的简单ListView。我已经用ConstraintLayout为项目布局建模。一切正常,除非某个文本视图包含长文本,使其位于第二行并与下一个文本重叠。如何使项目仅在需要时垂直展开 我的列表视图: <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
tools:context="org.altervista.realms.biomap.fragments.EditFragment">
<ListView
android:id="@+id/recordsListView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:fillViewport="true"
android:divider="@drawable/list_divider"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
我想让第三项(和第三项只)垂直扩展。
谢谢大家!
编辑:
我注意到,只有文本略长于行时,才会出现此问题。如预期的那样,使用较长的文本会导致文本视图展开
在我看来,它使用父宽度来决定何时展开布局,而使用textview宽度来决定何时开始新行
请注意,下面图像的XML是相同的。我只更改了文本字符串
从您的editRecordLocHab
textView中删除app:layout\u constraintBottom\u toBottomOf=“parent”
属性解决了我复制的代码中的问题。删除app:layou constraintBottom\u tobottomf=“parent”
您提供的属性editRecordLocHab
textView解决了我复制的代码中的问题。使用RelativeLayout
怎么样?谢谢,我会试试。使用RelativeLayout
怎么样?谢谢,我会试试。谢谢!在最后一行下方设置边距时,需要该约束。删除它会导致最后一行接触视图的底部,而忽略底部边距。我认为ConstraintLayout不能很好地处理边距(无论如何,不是我期望的方式:),所以它解决了您在问题中面临的问题?是的。我在最后一个元素下面添加了一个填充,而不是一个空白,现在一切似乎都在正确的位置。再次感谢你。很高兴知道!也许你可以把这个问题标记为已回答?对不起。我给+1而不是检查它。完成:)谢谢!在最后一行下方设置边距时,需要该约束。删除它会导致最后一行接触视图的底部,而忽略底部边距。我认为ConstraintLayout不能很好地处理边距(无论如何,不是我期望的方式:),所以它解决了您在问题中面临的问题?是的。我在最后一个元素下面添加了一个填充,而不是一个空白,现在一切似乎都在正确的位置。再次感谢你。很高兴知道!也许你可以把这个问题标记为已回答?对不起。我给+1而不是检查它。完成:)
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="wrap_content"
android:background="@drawable/record_row"
android:longClickable="true"
>
<Button
android:id="@+id/editRecordDeleteButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:background="@drawable/button"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:minHeight="40dp"
android:minWidth="40dp"
android:text="@string/icon_delete"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
/>
<TextView
android:id="@+id/editRecordDate"
android:text="21/06/2015"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="8dp"
android:layout_marginTop="4dp"
/>
<TextView
android:id="@+id/editRecordSpecies"
android:text="Russola Magnificens Russola Magnificens"
android:textColor="#000000"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/editRecordDate"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/editRecordAbundance"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="4dp"
/>
<TextView
android:id="@+id/editRecordLocHab"
android:text="Faggeta acidofila a Luzula Croce di Forcella Piccola"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginLeft="8dp"
android:layout_marginBottom="4dp"
app:layout_constraintRight_toLeftOf="@+id/editRecordDeleteButton"
android:layout_marginRight="8dp"
android:layout_marginTop="4dp"
app:layout_constraintTop_toBottomOf="@+id/editRecordSpecies"
/>
<TextView
android:id="@+id/editRecordTime"
android:text="14:44"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toLeftOf="@+id/editRecordDeleteButton"
android:layout_marginRight="8dp"
android:layout_marginTop="4dp"
/>
<TextView
android:id="@+id/editRecordAbundance"
android:text="2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/editRecordTime"
app:layout_constraintRight_toLeftOf="@+id/editRecordDeleteButton"
android:layout_marginRight="8dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
/>
</android.support.constraint.ConstraintLayout>