2016-12-14 63 views
0

我设置背景图片为TextView背景图像(TextView的)大如TextView的内容

<TextView 
    ... 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:background="@drawable/fumetto" 
    ... 
/> 

的问题是,现在的TextView尺寸不一样大,它的内容,但它是作为作为背景图像很大。

有没有办法让背景图像适应TextView大小,而不是让TextView适应其背景图像的大小?

预先感谢您。

+0

这应该工作正常。请检查你的父母布局或张贴一些更多的代码。 –

回答

1

您应该使用9 Patch Drawable。 这是developer guide

+0

谢谢你的帮助。我做了一个9补丁图像,但现在android studio告诉我,有一个“重复”resorces错误,因为现在我有fumetto.png和fumetto.9.png。 如果删除fumetto.png(甚至在清理和重新整理项目之后),我会得到另一个错误。 你知道如何在android studio上解决这个问题吗? – MDP

+0

删除drawable后会出现什么错误? @MDP –

0

从资源

<TextView 
     android:id="@+id/btn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:background="@drawable/button_border" 
    android:text="adswss" /> 

使用形状绘制button_border

`<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <shape android:shape="rectangle" > 
      <corners android:radius="15dp"></corners> 
      <stroke android:width="2dp" android:color="@color/color_bg" /> 
     </shape> 
    </item> 
</selector>'