这里的某些东西效果不佳。
我需要的是:使用带有图案背景的RelativeLayout
填充ImageView
的一部分。
我做了什么:如果我将定义的数字(DP
)放到ImageView
高度,它就可以了。但这不是我需要的,因为RelativeLayout
的高度为wrap_content
。我需要图案填充所有亲戚,边距为13dp
的顶部和底部。 (和10dp
宽度)。
如果我将匹配父项置于ImageView
高度(我认为这是正确的解决方案),它就不起作用(它只显示一行)。
这就是我需要的: http://postimg.org/image/csr16zccn/
以下是RelativeLayout
的代码:
<RelativeLayout
android:id="@+id/relative2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/relative"
android:paddingBottom="13dp"
android:paddingTop="13dp" >
<ImageView
android:id="@+id/pattern"
android:layout_width="10dp"
android:layout_centerVertical="true"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:src="@drawable/row_pattern" />
<TextView
android:id="@+id/title"
android:layout_width="245dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:paddingLeft="18dp"
style="@style/p_general" />
</RelativeLayout>
这是row_pattern.xml
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/pattern"
android:tileMode="repeat"
android:dither="true" />
答案 0 :(得分:1)
你可以将layout_alginTop="@+id/title"
和layout_alginBottom="@+id/title"
属性设置为ImageView
,而不是你的图片会填充标题的高度。
<RelativeLayout
android:id="@+id/relative2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/relative"
android:paddingBottom="13dp"
android:paddingTop="13dp" >
<TextView
android:id="@+id/title"
android:layout_width="245dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:paddingLeft="18dp"
style="@style/p_general" />
<ImageView
android:id="@+id/pattern"
android:layout_width="10dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alginTop="@+id/title"
android:layout_alginBottom="@+id/title"
android:src="@drawable/row_pattern" />
</RelativeLayout>
答案 1 :(得分:0)
如果父母有match_parent
,您不能wrap_content
孩子。它没有意义。孩子不能匹配没有定义维度的父母。您可以为父级提供高度,也可以只为图像指定高度。或者你可以wrap_content
你的图像(图像视图知道如何显示你的图像,但在这种情况下,它将显示源的分辨率,你可能不想这样)。