我正在尝试从Google's Material Design Guildlines为列表组件创建以下列表视图项。
因此,它应包含所描述的不同视图:
我认为不可能只为TextView的第一行设置保证金。
手动缩进:
android:text=" - I'll be in your neighborhood doing errands this weekend. Do you want to join us?"
如果TextView Content
显示HTML格式的代码,我该如何设置缩进。
<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="match_parent"
android:minHeight="84dp"
android:paddingTop="16dp">
<ImageView
android:id="@+id/user_avatar"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:src="@mipmap/ic_launcher"/>
<TextView
android:id="@+id/time_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
android:text="Saturday"
android:textAppearance="@style/TextAppearance.AppCompat.Small" />
<TextView
android:id="@+id/subject_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="100dp"
android:layout_marginLeft="72dp"
android:layout_marginRight="100dp"
android:layout_marginStart="72dp"
android:ellipsize="end"
android:maxLines="1"
android:text="Brunch this weekend? Just making line long"
android:textAppearance="@style/TextAppearance.AppCompat.Headline" />
<TextView
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/subject_text"
android:layout_alignStart="@+id/subject_text"
android:layout_below="@+id/subject_text"
android:ellipsize="end"
android:maxLines="2"
android:text=" - I'll be in your neighborhood doing errands this weekend. Do you want to join us?"
android:layout_marginRight="16dp"
android:lineSpacingExtra="4dp"
android:layout_marginEnd="16dp"
android:textAppearance="@style/TextAppearance.AppCompat.Menu" />
<TextView
android:id="@+id/user_fullName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/subject_text"
android:layout_alignStart="@id/subject_text"
android:layout_below="@+id/subject_text"
android:layout_marginEnd="150dp"
android:layout_marginRight="150dp"
android:ellipsize="end"
android:maxLines="1"
android:text="Ali Connors, has long name"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@+id/content"
android:layout_alignLeft="@+id/subject_text"
android:layout_alignStart="@+id/subject_text"
android:layout_marginTop="16dp"
android:background="#9e9e9e" />
</RelativeLayout>
答案 0 :(得分:2)
取出user_fullName
视图。您将把所有内容都放在content
视图中。
您可以在同一TextView
中使用多种字体样式。你将使用它来获得这种外观。
不幸的是,您无法在布局XML中指定标记,因此您无法看到文本在预览模式下的外观。你必须在代码中执行:
contentView.setText(Html.fromHtml("<font color=\'black\'>" + username + "</font> — " + TextUtils.htmlEncode(content));
或其他方法:
SpannableStringBuilder ssb = new SpannableStringBuilder();
ssb.append(username);
ssb.setSpan(new TextAppearanceSpan(context, android.R.style.TextAppearance_Material_Menu), 0, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
ssb.append(" \u2014 ");
ssb.append(content);
contentView.setText(ssb);