Android LinearLayout中實現水平方向上的兩個textview一個居左,一個居右的效果

<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一個居左,一個居右的效果。 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章