我有一个相当简单的布局,其中包含一个图像和一些包装在垂直LinearLayout中的文本视图。每当我将这个布局的背景设置为9patch时,布局的高度似乎被设置为9patch的高度(即使9patch似乎成功地拉伸为布局的高度)。
如果我使用纯色背景色,布局的高度将按预期工作。
这是一个带有9补丁的截图:
这是一个带有纯色背景的屏幕截图,而不是9patch (请注意文本现在是如何在布局中居中的):
最后,下面是XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/show_gray"
android:gravity="center_vertical"
android:orientation="horizontal" android:weightSum="5">
<ImageView
android:id="@+id/imageView1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:scaleType="centerCrop"
android:src="@drawable/temp_featured_banner" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#FF0000"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="30dp" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textColor="@color/white" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Small Text"
android:textColor="@color/white" />
</LinearLayout>
</LinearLayout>
..。以防万一,这里有一个draw9patch的屏幕截图,显示了我的9补丁可绘制:
我怀疑LinearLayout没有比9补丁的自然大小高(所以没有什么可拉伸的……),所以我将9补丁的高度减少了50%。这个问题仍然存在。
有什么想法吗?
发布于 2012-04-04 20:35:37
九个补丁的顶部和左侧指的是图像的“可伸展”区域。九个补丁的右边和底部定义了内容应该放在哪里--目前,您只是告诉它去猜测(它通过将所有内容放在由左上角圆点指定的行中来进行猜测)。从我从你的图像中可以看出,你可能想要在9补丁的右侧从上到下(当然,省略了角)一条实心的黑线,并在底部的右上角的黑点上匹配一个点。这将告诉OS将内容放在与映像相关的位置,以便它更好地知道如何拉伸映像。
发布于 2012-04-04 16:56:48
在9补丁程序中,在底部和右侧绘制线条,以选择可以“折叠”的区域。也许能解决你的问题。
http://developer.android.com/guide/developing/tools/draw9patch.html
https://stackoverflow.com/questions/10015761
复制