如何使 LinearLayout 中的 TextView 填充剩余空间并被截断

黄金罢工

我有一个ListView包含一些行的行,尤其是在 2 中组合类别距离的行TextView

  • 类别的项目可以包含一个或多个类别,所以这TextView一定是truncable
  • 距离如果用户已允许的地理位置项时,才显示,所以这TextView可以被隐藏
  • 在这种情况下,类别项必须填充所有行的宽度

预期结果类似于 iOS 上的地图应用程序的屏幕截图: 地图截图

我试图用 LinearLayout 来做到这一点,但这并没有按预期工作:

<LinearLayout android:id="@+id/AffiliateCellDetail"
              android:layout_below="@id/AffiliateCellTitle"
              android:layout_height="wrap_content"
              android:layout_width="match_parent" >
    <TextView android:id="@+id/AffiliateCellCategories"
              android:layout_height="wrap_content"
              android:layout_width="wrap_content"
              android:ellipsize="end"
              android:singleLine="true"/>        
    <TextView android:id="@+id/AffiliateCellDistance"
              android:layout_height="wrap_content"
              android:layout_width="wrap_content"/>         
</LinearLayout>   

有没有更好的方法来实现这一目标?

黄金罢工

我终于通过使用实现了这一点ConstraintLayout

<android.support.constraint.ConstraintLayout
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/AffiliateCellDetail"
        android:layout_below="@id/AffiliateCellTitle"
        android:layout_height="wrap_content"
        android:layout_width="match_parent" >
    <TextView android:id="@+id/AffiliateCellCategories"
              android:layout_height="wrap_content"
              android:layout_width="0dp"
              android:ellipsize="end"
              android:singleLine="true"
              app:layout_constraintHorizontal_chainStyle="packed"
              app:layout_constraintHorizontal_bias="0"
              app:layout_constraintWidth_default="wrap"
              app:layout_constraintTop_toTopOf="parent"
              app:layout_constraintLeft_toLeftOf="parent"
              app:layout_constraintRight_toLeftOf="@+id/AffiliateCellDistance"/>        
    <TextView android:id="@+id/AffiliateCellDistance"
              android:layout_height="wrap_content"
              android:layout_width="wrap_content"
              app:layout_constraintBaseline_toBaselineOf="@+id/AffiliateCellCategories"
              app:layout_constraintLeft_toRightOf="@+id/AffiliateCellCategories"
              app:layout_constraintRight_toRightOf="parent"/>                
</android.support.constraint.ConstraintLayout>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章