简体   繁体   English

如何在android小部件背景中显示图像?

[英]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,它将src设置为提供的android小部件4x1框架图像。这是小部件布局代码。

<?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. @ drawable / widgetinitial在developer.android.com(AppWidget设计准则)中保存着widgetinitial.png图像示例4x1。(4x1_Widget_Frame_Portrait.psd)我要做的是在交付的框架内显示图像,而不是框架图像消失,仅显示我要显示的图像。 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. 另一个问题-我想我在几个论坛中看到过AbsoluteLayout是Android 2.1及更高版本不推荐使用的功能。 Is that correct? 那是对的吗? and does using AbsoluteLayout throws any force close or other exceptions? 并使用AbsoluteLayout引发任何强制关闭或其他异常吗?

AbsoluteLayout is deprecated. 不推荐使用AbsoluteLayout。 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 . 为此,我将使用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页的末尾

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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