【发布时间】:2010-07-18 11:31:39
【问题描述】:
我定义了一个drawable
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#ffffffff" />
<size android:width="60dp"
android:height="40dp" />
</shape>
但是如何在layout定义中使用呢?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:src="@drawable/ic_title"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
/>
</LinearLayout>
我仍然只能看到黑色背景。
已编辑:
原来我在drawable xmlns 声明中错过了一个:。现在这个例子可以在 Gingerbread 设备上运行 :)
【问题讨论】:
-
愚蠢的问题,但
ic_title是您定义的可绘制对象的名称吗?另外,您可以在LinearLayout上设置android:background -
是的,ic_title 是我上面定义的drawable。我不想设置 android:background,这不是想要的效果。我可能会将更多 ImageView 放入 LinearLayout。