1

我對使用下面的屬性有點困惑。佈局開始結束,左右概念

> android:layout_marginRight and android:layout_marginEnd 
> android:layout_marginLeft and android:layout_marginStart 
> android:layout_toLeftOf and android:layout_toStartOf 
> android:layout_toRightOf and android:layout_toEndOf 
> android:layout_gravity="right|end" 
> android:layout_gravity="left|start" 

下面是我提到的一些事實。請糾正我,如果我錯了。

  • 爲了支持LTR和RTL佈局和之前的API級別支持的版本17 是建議把上面的屬性總是成對..

  • 「開始」和「結束」在API級別17中加入概念並且將
    優先用於與API級LTR設備> = 17,「右」和「左」 概念將優先爲LTR設備與API級0​​17

  • 如果OU我們可以忽略「right」和
    「左」屬性並僅使用「開始」和「結束」屬性

  • 「開始」和「結束」概念將優先於所有RTL 設備

此外,我想知道是否有在性能/優化方面的任何不利影響,如果我在上面添加成對屬性喜歡 -

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="right|end" 
    android:layout_marginRight="@dimen/dp10" 
    android:layout_marginEnd="@dimen/dp10" 
    android:layout_marginLeft="@dimen/dp10" 
    android:layout_marginStart="@dimen/dp10" 
    android:layout_toLeftOf="@+id/bar" 
    android:layout_toStartOf="@+id/bar" 
    /> 

回答

1

支持RTL在你的應用程序你應該:

  • 如果您的應用程序API級別> = 17,你應該使用「開始」和「結束」,而不是「左」和「右(例如:layout_marginStart)
  • 如果您的應用程序API級別< 17則除了「左」和「右」之外,還應該加上「開始」和「結束」。換句話說 - 同時使用layout_marginRight和layout_marginEnd 換句話說你的任何觀點應該是這樣的: 機器人:ID = 「@ + ID/TextView的」

    android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_marginStart="16dp" 
        android:layout_marginTop="20dp" 
        android:text="@string/text_Field" 
        android:textSize="24sp" 
        android:textStyle="bold" 
        app:layout_constraintStart_toStartOf="parent" 
        app:layout_constraintTop_toBottomOf="@+id/imageView" /> 
    

    注:機器人:layout_marginStart = 「16DP」

Source