用到了LinearLayout,LinearLayout中有两个textView,想让其中一个左对齐,一个右对齐。
经尝试,gravity="right"无效,遂google。发现,大部分说法是layoutwidth="match_parent",不能设置为wrap_content.
最终成功,代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<TextView
android:id="@+id/title_item"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginTop="2dp"
android:textSize="20sp"
android:layout_gravity="start"
android:layout_marginLeft="10dp"/>
<TextView
android:id="@+id/note_time"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="10dp"
android:layout_marginTop="2dp"
android:layout_gravity="end"
android:textSize="14sp" />
</LinearLayout>
<TextView
android:layout_marginTop="3dp"
android:layout_marginBottom="2dp"
android:id="@+id/content_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:maxEms="18"
android:singleLine="true"
android:ellipsize="end"
android:layout_marginLeft="10dp"
/>
</LinearLayout>