user963241
user963241

Reputation: 7038

android:drawableRight vs android:drawableEnd

If I use android:drawableRight="@drawable/my_image"on a button:

<Button
        android:id="@+id/my_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/my_button"
        android:drawableRight="@drawable/my_image"
        android:drawablePadding="4dp"/>

Then a warning/suggestion in editor tells me:

Consider replacing android:drawableRight with android:drawableEnd="@drawable/my_image" to better support right-to-left layouts

What does this mean? Can you no longer use android:drawableRight ?

Upvotes: 4

Views: 5332

Answers (2)

Daniel
Daniel

Reputation: 2373

Certain countries' languages are read right to left. If you don't code your layout elements with this in mind, your app may not look correctly in their devices. Essentially, replace left with start & right with end in your layout elements. This applies to both the XML attributes & the values of said XML attributes. You can see the results & play around with your layouts under Right-to-Left conditions if you go under Developer Options & tap Force RTL Layout.

Here is an example of a layout I used recently. Pay careful attention to the use of End in both an XML attribute & as a value of an XML attribute.

<LinearLayout
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      android:gravity="end">

    <TextView
        android:id="@+id/bid_price"
        style="@style/BidPriceTextStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingEnd="10dp"
        tools:text="1000.00" />
    <TextView
        android:id="@+id/change"
        android:background="@drawable/percent_change_pill"
        style="@style/PercentChangeTextStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingStart="3dp"
        android:paddingEnd="3dp"
        tools:text="100%" />
</LinearLayout>

Upvotes: 4

ugur
ugur

Reputation: 3654

In addition to Daniel's answer drawableEnd and drawableStart can be used for API_14+. So if you are using minSdkVersion < 14, you must also use drawableRight and drawableLeft besides drawableEnd and drawableStart.

Upvotes: 2

Related Questions