简体   繁体   中英

How to display the image inside the android widget background?

I have a widget layout xml which sets the src to the delivered android widget 4x1 frame image.Here is the widget layout code.

<?xml version="1.0" encoding="utf-8" ?> 
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"  
 android:id="@+id/tuwidget" android:layout_width="fill_parent" 
 android:layout_height="fill_parent">
<ImageView android:id="@+id/tuwidget_img_btn" 
 android:src="@drawable/widgetinitial" 
 android:layout_width="fill_parent" 
 android:layout_height="wrap_content" /> 
</AbsoluteLayout>

@drawable/widgetinitial holds the widgetinitial.png image example 4x1 at developer.android.com (AppWidget design guidelines).(4x1_Widget_Frame_Portrait.psd) What I am trying to do is display an image inside the delivered frame instead what happens is the frame image goes away and only the image I am trying to display shows up. How can I display the image inside the bounding box or the background? Any help is much appreciated.

Another question - I think I saw in a couple of forums AbsoluteLayout is a deprecated feature for Android 2.1 and above. Is that correct? and does using AbsoluteLayout throws any force close or other exceptions?

AbsoluteLayout is deprecated. It doesn't throw any exceptions, but its generally a bad idea to use it because it is really hard to design a layout that will work on all screen sizes. There is generally a better way to do it using a different layout.

In your case, I don't follow exactly, but it sounds like you want to layer two widgets on top of each other? An image with a frame? To do so, I'd use a FrameLayout . This is designed for having multiple layers of images.

Common layout objects is also a good guide to the basic layout types.

看看此pdf第2页的末尾

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM