Android:Drawableleft Margin And/Or Padding

How to set margin or padding for DrawableLeft Icon in android

Instead of placing as a DrawableLeft, I suggest you to take an ImageView ... So that you can have more control on the image.

You can have many functionalies with ImageView, but in EditText you cannot.

Lastly, place them both in RelativeLayout.

Hopefully it will work as expected.

Android TextView drawable, change padding between drawable and text?

You'll need to combine drawablePadding and padding to get the desired result.

Padding between Textview border and drawableLeft

The problem is your are using image from mipmap folder. mipmap is only used for launcher icons and its added extra padding and elevation when show on view.

Always keep resource icons in drawable folder and use it as
@drawable/ic_italian_plate.

#. You can add padding and corners to custom drawable using <padding> and <corners>.

Update plate_textview.xml as below:

<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android">

<solid
android:color="@android:color/white"/>

<stroke
android:width="2dp"
android:color="@color/black"/>

<padding
android:top="2dp"
android:bottom="2dp"
android:left="2dp"
android:right="8dp" />

<corners
android:radius="2dp" />
</shape>

Update TextView as below:

<TextView
android:id="@+id/txtPlate2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:gravity="center"
android:drawableStart="@drawable/ic_italian_plate"
android:textColor="@color/black"
android:textSize="40sp"
android:text="I-123-4568"
android:textAlignment="center"
android:background="@drawable/plate_textview"/>

OUTPUT:

enter image description here

Hope this will help~

Gap between left drawable and text in a EditText

You should add android:drawablePadding attribute to your EditText. Example layout with 10dp drawable padding:

<EditText
android:id="@+id/emailEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/sign_up_edittext_vertical_top_margin"
android:drawableLeft="@drawable/email_drawable"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:drawablePadding="10dp"
android:singleLine="true" />

Command and Property order for Margin and Padding in Android Java Code

The answer to the other question is "no" unless you write a custom ViewGroup with a custom layout attribute. In general, when all sides are specified in the Android environment, the order of side specification is "left,top, right, bottom." I don't think this is a canonical order but is my observation.

As for changing margins in Java where lp is the layout params for a view:

lp.setMargins(left, top, right, bottom);
view.setLayoutParams(lp);

See ViewGroup.LayoutParams.

For padding you can use View.setPadding:

view.setPadding(left, top, right, bottom)

Notice that margins are managed by ViewGroups and padding is managed by Views.



Related Topics



Leave a reply



Submit