<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="張三"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="李四"/>
</LinearLayout>
設置 android:layout_width="0dp",android:layout_height="wrap_content",android:layout_weight="1"這三個屬性後,就會把match_parent剩下的佈局給撐滿,所以會把右邊那個textView擠到最右端。
這樣就能達到在LinLinearLayout中水平方向上的有兩個textview一個居左,一個居右的效果。