?仅仅因为需要处理多少个分辨率,使用固定像素大小的图像是一个糟糕的主意。如果您尝试使用的背景类型可能,您应该考虑使用9补丁的图像。然后,只需将layout_width设置为fill_parent,并根据需要自动调整其大小。
http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
编辑:很难说究竟你有什么,但我建议像下面的,而不是一个ImageView的(在绘图资源文件夹的地方)
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="{whatever height you have set}"
android:id="@+id/header_relative_layout"
android:background="@drawable/gradient"
>
<ImageView
android:id="@+id/header_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_alignParentLeft="true"
android:src="@drawable/header_image"
/>
<TextView
android:id="@+id/header_textview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/header_text"
android:layout_toRightOf="@id/header_imageview"
android:layout_marginLeft="10dp"
/>
</RelativeLayout>
gradient.xml
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<gradient
android:startColor="#FFFF0000"
android:endColor="#80FF00FF"
android:angle="270"
/>
</shape>
我还没有真正编译过这个,但它应该相当接近。这样,您不必每次都生成图像,并且宽度将自动填充以获取屏幕的整个宽度。
这是否帮助?
图像在运行时创建。它只是绘制一个褪色的背景,将一些固定大小的图标和文本放在顶部。没有什么花哨。 – 2010-09-24 12:38:27
我想我明白你要去的地方,除了背景。你喜欢背景的渐变,还是仅仅是一种颜色?我已经在上面添加了一个建议示例。 – kcoppock 2010-09-24 14:16:48
是的,我有一个背景渐变。然后,我在左侧放置一个图标,并在图标的右侧放置文字。由于资源保存在数据库而不是RES文件夹中,因此我只能在运行中创建图片。我开始相信我无法按照我打算的方式做到这一点。 – 2010-09-28 15:31:08