Android Developer
Android Developer

Reputation: 9653

Layout-start-end,left-right concepts

I am little confused regarding usage of below attributes.

> 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"

Below are the some of facts which i have mentioned.Please correct me if i am wrong.

Also I would like to know if there is any adverse effect in terms of performance/optimization if i add above attributes in pairs like-

 <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"
     />

Upvotes: 3

Views: 6240

Answers (1)

researcher
researcher

Reputation: 1788

To support RTL in your apps you should:

  • If your app API level >=17 you should use “start” and “end” instead of “left” and “right (for example: layout_marginStart)
  • If your app API level <17 then you should add “start” and end” in addition to “left” and “right”. In other words - use both layout_marginRight and layout_marginEnd In other words any of your view should look like this: android: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" />
    

    Note: android:layout_marginStart="16dp"

Source

Upvotes: 7

Related Questions