我有以下问题:
我有一个Android应用程序,它使用列表,自定义列表项和一些填充了文本的TextView。
如何使该文本最多包含3行而不与正确的数字重叠(25)?
这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout">
<ImageView
android:id="@+id/imageViewAlertList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:src="@drawable/ellipse103"/>
<TextView
android:id="@+id/textViewDistanceLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:hint="Distance:"
android:layout_toRightOf="@+id/imageViewAlertList"
android:layout_alignBottom="@+id/imageViewAlertList"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textViewDistanceKmListItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:hint="N/A"
android:layout_toRightOf="@+id/textViewDistanceLabel"
android:layout_alignBottom="@+id/imageViewAlertList"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_toRightOf="@+id/imageViewAlertList"
android:id="@+id/linearLayout2">
<TextView
android:id="@+id/textViewAlertTimeListItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.20"
android:hint="Test minutes ago"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/textViewAlertDescriptionListItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:ellipsize="@+id/textViewAlertBusNumberListItem"
android:singleLine="false"/>
</LinearLayout>
<LinearLayout
android:id="@+id/id_iancu_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp">
<TextView
android:id="@+id/textViewAlertBusNumberLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Channel"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/textViewAlertBusNumberListItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
</RelativeLayout>
如果它通过3行,我希望它显示一些点。
提前致谢!
答案 0 :(得分:0)
使用权重属性时,请将宽度设置为0dp而不是wrap_content。我也更喜欢使用整数(尽管我不知道它是否有任何区别)。 要设置最大行,只需使用maxLines属性。对于点使用:
android:ellipsize="end"
答案 1 :(得分:0)
我会尝试这样的事情,创建2个水平布局,一个堆叠在另一个之上,这应该可以,然后你只需要玩填充。
<RelativeLayout
android:id="@+id/linearLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageViewAlertList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ellipse103"/>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_toRightOf="@id/imageViewAlertList">
<TextView
android:id="@+id/textViewAlertTimeListItem"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:hint="Test minutes ago"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/textViewAlertBusNumberLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Channel"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<LinearLayout
android:id="@+id/id_iancu_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_toRightOf="@id/imageViewAlertList"
android:layout_below="@id/linearLayout2">
<TextView
android:id="@+id/textViewAlertDescriptionListItem"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:ellipsize="end"
android:singleLine="true"/>
<TextView
android:id="@+id/textViewAlertBusNumberListItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<TextView
android:id="@+id/textViewDistanceLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:hint="Distance:"
android:layout_toRightOf="@+id/imageViewAlertList"
android:layout_alignBottom="@+id/imageViewAlertList"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textViewDistanceKmListItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:hint="N/A"
android:layout_toRightOf="@+id/textViewDistanceLabel"
android:layout_alignBottom="@+id/imageViewAlertList"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>