开发者

How to use a ShapeDrawable with an xml layout resource

开发者 https://www.devze.com 2023-02-12 09:27 出处:网络
I would like to be able to define a ShapeDrawable in my layout file and then inflate that so I can draw on it.

I would like to be able to define a ShapeDrawable in my layout file and then inflate that so I can draw on it. I have followed the tutorial on the android developers' site but I cannot see how I reference my ShapeDrawa开发者_Python百科ble in my main class file.

How do I actually inflate it?

I have put the following the following into my layout file:

<com.example.shapedrawable.CustomDrawableView 
    android:id="@+id/customDrawableView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />


Once you have defined the ShapeDrawable in its own XML file, you need to add the following to the layout.xml where you want it to be included:

<ImageView
    android:src="@drawable/shapeDrawable_filename"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    />

If you want to do it programmatically, I don't have an answer (yet), but from your question, it seems this should work!

Let me know if that helps ;)

0

精彩评论

暂无评论...
验证码 换一张
取 消