10
我有一个平铺的位图,我用作View
背景。这个View
,比方说,有android:layout_height="wrap_content"
。问题是背景中使用的位图高度参与视图的测量,增加了高度。当View
的内容的大小小于用作瓦片背景的位图的高度时,可以注意到这一点。平铺背景推着它的视图尺寸
让我给你看一个例子。瓷砖位图:
位图绘制(tile_bg.xml
):
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/tile"
android:tileMode="repeat"/>
布局:
<?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:orientation="vertical"
android:background="#FFFFFF">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/tile_bg"
android:text="@string/hello"
android:textColor="#000000" />
</LinearLayout>
它的样子:
TextView
的高度最终成为位图的高度。我期望的是位图被剪裁到View
的大小。
有什么办法可以达到这个目的吗?
注:
- ,因为背景需要在瓷砖时尚的方式来重复,拉伸,我不能使用9patch绘项目是不是一种选择。
- 我不能设置一个固定的高度为
View
,这取决于孩子的 - 这种奇怪的行为发生,因为我当
View
的大小小于之前解释(我在ViewGroup
使用本)位图的大小,否则位图会被正确重复剪切(即,如果视图大小是位图大小的1.5倍,则最终会看到位图的1.5倍)。 - 该示例处理高度,但使用宽度相同。
优秀的答案,谢谢! – aromero 2012-01-20 20:13:37