2010-06-21 40 views

回答

3

我现在有这个工作,我没有必要乱七八糟的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); 
     } 
4

答案是“不完全是,”至少没有明确的方式你的意思,但你应该能够使你的形象出现是外排只需使用列表项目的背景图像看起来像列表的边缘,与实际所在的位置相距几个像素。然后,您可以将要显示的图元向右对齐,并向不包含的元素添加一些右侧填充/边距。

+0

我不知道这将如何工作,因为该行的高度可能会改变... – Ben 2010-06-22 04:11:33

+0

我不知道我是否清楚,该图像应该是您用于该行的视图的一个子对象,并在其右上方对齐。如果为包含边框和空白的列表使用背景(可能是九块拼贴),但在右侧没有填充区域(也就是九块的内容区域与右边界)。但是因为它仍然是列表行中的适当子项,所以无论高度如何,溢出图像都将针对每一行正确定向。 – 2010-06-22 13:58:21

+0

我想可能有一种方法来使用AbsoluteLayout来做到这一点,我意识到这是过时的,但也许它可能会工作? – Ben 2010-06-22 15:02:10

1

你应该能够实现这个使用android:clipChildren="false"android:clipToPadding="false"于眼前的父视图,然后android:clipChildren="false"上的所有祖先视图组,然后戴上图像视图阴性切缘;即android:layout_marginLeft="-10dp"

我花了一段时间了解这些工作,特别是android:clipChildren="false"。谷歌说:“定义孩子是否被限制在内界限内”,关键在于孩子的“边界”不是父视图组的边界,而是视图边界的界定通过它的布局属性,这就是为什么你需要它始祖树。