Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are paddingStart and paddingEnd?

Since few times the autocomplete box from Eclipse propose android:paddingStart android:paddingStop when I'm writing xml layout files.

I don't really understand what those attributes are supposed to do.

The eclipse/javadoc documentation is not really helpful : Sets the padding, in pixels, of the start edge; see padding. and the online documentation does not make any reference to those attributes : http://developer.android.com/reference/android/view/View.html

Could you explain me ?

like image 517
Mathieu Avatar asked Aug 28 '12 13:08

Mathieu


2 Answers

After reading into the Android source code (View.java) it seems paddingStart and paddingEnd are helpful to take care of letter direction (left to right of right to left) defined by the user.

Thus, paddingStart is interpreted as paddingLeft in LTR (left-to-right) languages and paddingRight in RTL (right-to-left) languages.

Source code from View.java (android-4.0.1) :

    switch (getResolvedLayoutDirection()) {
        case LAYOUT_DIRECTION_RTL:
            // Start user padding override Right user padding. Otherwise, if Right user
            // padding is not defined, use the default Right padding. If Right user padding
            // is defined, just use it.
            if (mUserPaddingStart >= 0) {
                mUserPaddingRight = mUserPaddingStart;
            } else if (mUserPaddingRight < 0) {
                mUserPaddingRight = mPaddingRight;
            }
            if (mUserPaddingEnd >= 0) {
                mUserPaddingLeft = mUserPaddingEnd;
            } else if (mUserPaddingLeft < 0) {
                mUserPaddingLeft = mPaddingLeft;
            }
            break;
        case LAYOUT_DIRECTION_LTR:
        default:
            // Start user padding override Left user padding. Otherwise, if Left user
            // padding is not defined, use the default left padding. If Left user padding
            // is defined, just use it.
            if (mUserPaddingStart >= 0) {
                mUserPaddingLeft = mUserPaddingStart;
            } else if (mUserPaddingLeft < 0) {
                mUserPaddingLeft = mPaddingLeft;
            }
            if (mUserPaddingEnd >= 0) {
                mUserPaddingRight = mUserPaddingEnd;
            } else if (mUserPaddingRight < 0) {
                mUserPaddingRight = mPaddingRight;
            }
    }
like image 114
Mathieu Avatar answered Oct 16 '22 07:10

Mathieu


Padding is used to add a blank space between a view and its contents.

  • android:paddingStart Sets the padding at the start edge means at the left side of view
  • android:paddingEnd Sets the padding at the end edge means at the right side of view
  • android:paddingBottom Sets the padding at the bottom edge
  • android:paddingTop Sets the padding at the top edge

enter image description here

like image 36
Dinkar Kumar Avatar answered Oct 16 '22 08:10

Dinkar Kumar