如何在textView中为背景图像设置填充?

时间:2017-12-27 16:34:19

标签: android background-image textview

我正在创建一个calc应用程序。 如何设置填充以缩小背景图像.. 我想将this backspace background转换为this

之类的内容

我的TextView的xml:

public class ApplicationDbContext: DbContext
{
    public ApplicationDbContext()
    {
        while (!Debugger.IsAttached)
        {
            Thread.Sleep(100);
        }
    }
    ...
}

3 个答案:

答案 0 :(得分:0)

使用ImageView代替并给它填充:

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

为什么你需要Textview和背景图像呢? 您只需添加ImageViewImageButton

即可

答案 1 :(得分:0)

你应该像这样使用imageButton而不是TextView:

<ImageButton
  android:id="@+id/delete_button"
  android:layout_width="70dp"
  android:layout_height="40dp"
  android:background="@drawable/delete_icon"
  android:layout_margin="16"/>

答案 2 :(得分:0)

我认为不止一种方式

第一种方式,您必须将TextView扩展到新类并覆盖一些@override方法。并在xml中使用此类...这很难

第二种方式(推荐),使用Adobe Illustrator或Photoshop调整新的drawable并随意轻松实现

第三种方式,使用RelativeLayoutFrameLayout并以Imageview轻松的方式制作您想要的背景并完成工作

 <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>
相关问题