2013-06-21 62 views
0

我有此资源 enter image description here如何在android上设置自定义的可绘制背景?

我用这9个修补后的图像作为我的列表项背景。

enter image description here

,你可以看到,内容未正确放置在盒内:但是当我的布局XML是这个样子出事了。 这是我如何定义我的列表项的布局:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:padding="10dp" 
android:background="@android:color/transparent" > 

<ImageView 
    android:id="@+id/item_image" 
    android:layout_width="50dp" 
    android:layout_height="50dp" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" /> 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="10dp" 
    android:padding="5dp" 
    android:orientation="vertical" 
    android:layout_alignParentTop="true" 
    android:layout_toRightOf="@+id/item_image" 
    android:background="@drawable/chat_left" > 

    <TextView 
     android:id="@+id/item_text_1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textStyle="bold" 
     android:textColor="#8cc751" 
     android:textSize="20sp" 
     android:text="Name" 
     /> 
    <TextView 
     android:id="@+id/item_text_2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" 
     android:textColor="#909090" 
     android:textSize="14sp" 
     android:text="Message" 
     /> 
</LinearLayout> 

</RelativeLayout> 

我不知道为什么会这样。任何想法? 谢谢!

+0

它通常发生在9patch图像。从Drawables中删除这些文件,并将其从先前复制到的任何位置再次复制到Drawable文件夹 –

+0

您已经手动为图像视图提供了layout_width和layout_height .........尝试更改这两个参数以调整图像中的文本 – nidhi

回答

0

9补丁图像只是背景。你必须调整你的观点。请参阅..从您的图像M直接到N。因此,您可以将第二个textview或两者都移动到某个像素右侧,例如,您可以添加marginLeft

<TextView 
     android:id="@+id/item_text_2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" 
     android:layout_marginLeft="5dp" 
     android:textColor="#909090" 
     android:textSize="14sp" 
     android:text="Message" 
     /> 

我希望这个建议能帮到你。

相关问题