在列表视图中认为“外”框中的Android图像
我想有一个ImageView是ListView行项目的一部分,但它出现在行内外。这可能吗?如果是这样,怎么样?许多在此先感谢... alt text http://www.freeimagehosting.net/uploads/a7e703a33f.png在列表视图中认为“外”框中的Android图像
我现在有这个工作,我没有必要乱七八糟的Photoshop。我使用android xml完成了这一切。
做到这一点的方法是使用和,而不是使用<layer-list>
元件,而不使用填充,这样的:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="6dip" android:right="6dip" android:left="6dip">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:bottomRightRadius="2dip"
android:bottomLeftRadius="2dip" android:topLeftRadius="6dip"
android:topRightRadius="6dip" />
<solid android:color="@color/list_view_outline" />
</shape>
</item>
<item android:top="8dip" android:right="8dip" android:left="8dip">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:bottomRightRadius="2dip"
android:bottomLeftRadius="2dip" android:topLeftRadius="6dip"
android:topRightRadius="6dip" />
<solid android:color="@android:color/white" />
<stroke android:width="1dip" android:color="#BDBDBD" />
</shape>
</item>
然后只需使用标准列布局列表行:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/feed_list_row_content">
<ImageView android:id="@+id/author_image"
android:layout_width="44dip" android:layout_height="44dip"
android:layout_alignParentTop="true" android:layout_alignParentLeft="true"
android:src="@drawable/no_photo" android:layout_marginLeft="10dip"
android:layout_marginTop="10dip" />
<TextView android:layout_width="wrap_content"
android:layout_marginTop="10dip" android:layout_height="wrap_content"
android:layout_toRightOf="@id/author_image" android:id="@+id/feed_message_content"
android:layout_toLeftOf="@+id/action_button" />
<ImageView android:id="@id/action_button" android:src="@drawable/row_action"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentRight="true" android:layout_marginTop="20dip" />
我然后设置背景和基础d在自定义列表适配器getView()方法顶部&底部行呈现与中间行不同。
if(position == 0)
{
holder.contentLayout.setBackgroundResource(R.drawable.top_row);
} else if(position == posts.size() - 1)
{
holder.contentLayout.setBackgroundResource(R.drawable.bottom_row);
} else {
holder.contentLayout.setBackgroundResource(R.drawable.inner_row);
}
答案是“不完全是,”至少没有明确的方式你的意思,但你应该能够使你的形象出现是外排只需使用列表项目的背景图像看起来像列表的边缘,与实际所在的位置相距几个像素。然后,您可以将要显示的图元向右对齐,并向不包含的元素添加一些右侧填充/边距。
我不知道这将如何工作,因为该行的高度可能会改变... – Ben 2010-06-22 04:11:33
我不知道我是否清楚,该图像应该是您用于该行的视图的一个子对象,并在其右上方对齐。如果为包含边框和空白的列表使用背景(可能是九块拼贴),但在右侧没有填充区域(也就是九块的内容区域与右边界)。但是因为它仍然是列表行中的适当子项,所以无论高度如何,溢出图像都将针对每一行正确定向。 – 2010-06-22 13:58:21
我想可能有一种方法来使用AbsoluteLayout来做到这一点,我意识到这是过时的,但也许它可能会工作? – Ben 2010-06-22 15:02:10
你应该能够实现这个使用android:clipChildren="false"
和android:clipToPadding="false"
于眼前的父视图,然后android:clipChildren="false"
上的所有祖先视图组,然后戴上图像视图阴性切缘;即android:layout_marginLeft="-10dp"
。
我花了一段时间了解这些工作,特别是android:clipChildren="false"
。谷歌说:“定义孩子是否被限制在内界限内”,关键在于孩子的“边界”不是父视图组的边界,而是视图边界的界定通过它的布局属性,这就是为什么你需要它始祖树。
嗨,本,“行外”你的意思是绿色的图像? – Jorgesys 2010-06-21 22:55:04
是的绿色图像... – Ben 2010-06-22 04:12:14