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