如何使用XML形状drawable?(XML shape drawable not rendering desired color)

编程入门 行业动态 更新时间:2024-10-25 08:16:32
如何使用XML形状drawable?(XML shape drawable not rendering desired color)

我定义了一个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设备中使用:)

I defined a 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>

But how to use it in the layout definition?

<?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>

I still see only black background.

Edited:

It turned out I missed one : in the drawable xmlns declaration. Now this example works in the Gingerbread device :)

最满意答案

我有一个类似的问题,发现如果你删除大小的定义,它的工作原因有些。

去掉:

<size android:width="60dp" android:height="40dp" />

从形状。

让我知道如果这个工作!

I had a similar problem and found that if you remove the size definition, it works for some reason.

Remove:

<size android:width="60dp" android:height="40dp" />

from the shape.

Let me know if this works!

更多推荐

android,xmlns,drawable,电脑培训,计算机培训,IT培训"/> <meta name="descri

本文发布于:2023-07-28 01:17:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1298303.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   形状   XML   drawable   color

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!