How to set padding for background image in textView?

android background-image textview

493 观看

3回复

0 作者的声誉

I am creating a calc app. How to set padding to shrink the background image.. I want to convert this backspace background to something like this

My xml of TextView :

<TextView
        android:id="@+id/c_tv_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="fill"
        android:gravity="center"
        android:layout_columnWeight="1"
        android:layout_rowWeight="1"
        android:text=""
        android:background="@drawable/ic_backspace_black_24dp"
        android:padding="5dp"/>
作者: user8660130 的来源 发布者: 2017 年 12 月 27 日

回应 3


0

1155 作者的声誉

Use ImageView instead and give padding to it :

<ImageView
            android:padding="20dp"
            android:src="@drawable/ic_backspace_black_24dp"
            android:id="@+id/product_main_image"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
           />

and why you need Textview and Background image to that ? You can simply put ImageView or ImageButton

作者: Abubakker Moallim 发布者: 2017 年 12 月 27 日

0

1439 作者的声誉

You should use imageButton instead of TextView like this:

<ImageButton
  android:id="@+id/delete_button"
  android:layout_width="70dp"
  android:layout_height="40dp"
  android:background="@drawable/delete_icon"
  android:layout_margin="16"/>
作者: VolkanSahin45 发布者: 2017 年 12 月 27 日

0

725 作者的声誉

I suppose there's more than one way

First way, you have to extends TextView into new class and overwrite some @override methods. and use this class in xml... this is hard way

Second way (Recommended), use Adobe Illustrator or Photoshop to adjust a new drawable and make it easily as you like

Third way, use RelativeLayout or FrameLayout and make the background you want in a Imageview... easy way and do the job

 <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >

        <ImageView
            android:id="@+id/iv1"
            android:padding="your_padding_value"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_backspace_black_24dp"/>

        <TextView
            android:id="@+id/c_tv_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:padding="5dp"
            android:text=""
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            android:layout_alignBottom="@+id/iv1"
            android:layout_alignEnd="@+id/iv1"
            android:layout_alignStart="@+id/iv1"
            android:layout_alignTop="@+id/iv1"/>

    </RelativeLayout>
作者: Mohamed Embaby 发布者: 2017 年 12 月 27 日
32x32