【发布时间】:2017-11-24 21:04:13
【问题描述】:
我有一个列表项,它在 LinearLayout 中包含两个 TextView,垂直,一个在另一个之上。较高的数据不是静态的,我是从网上获取的,如果它太长,它会开始填充新行并且较低的视图消失。所以我想让第一个视图只填充一行。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:descendantFocusability="blocksDescendants"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="@dimen/margin_small">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com..view.ContactView
android:id="@+id/contact_icon"
style="@style/ContactListInitialsText"
android:layout_width="@dimen/contact_favorite_icon_size"
android:layout_height="@dimen/contact_favorite_icon_size"
app:request_photo="true"
app:show_contact_presence="true" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginStart="@dimen/margin_small"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="@+id/contact_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:textColor="@color/search_result_text_color"
android:textSize="16sp" />
<TextView
android:id="@+id/contact_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="marquee"
android:singleLine="true"
android:textSize="12sp" />
</LinearLayout>
<CheckBox
android:id="@+id/btn_star"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:button="@drawable/btn_star_select"
android:paddingEnd="@dimen/margin_small" />
</LinearLayout>
</RelativeLayout>
【问题讨论】:
-
用 1 添加 maxlines 属性
-
将 android:maxLines="1" 添加到 TextView
标签: android textview android-linearlayout