在android中掌握细节分裂样式

时间:2012-12-25 16:52:44

标签: android styling master-detail

这个问题在这里可能已被多次询问,但没有得出有用的答案。我把它放在这里可能的答案。随意改进。

问题:如何按照下图中突出显示的并排主要详情视图设置类似于详细视图样式的弹出窗口:

enter image description here

1 个答案:

答案 0 :(得分:15)

在这个解决方案中,我使用了9个补丁背景图像,为列表项定义了2种背景。因此,所选(已选中)列表项具有不同的背景,如下所示:

enter image description here(列表项)

enter image description here(所选项目)

enter image description here(列表项)

列表项布局的父视图是一个扩展LinearLayout(可以是任何ViewGroup)并实现Checkable的类。因此,当ListView设置为选择模式时,它可以自动检查/取消选中此视图。然后,分配给此视图的selector背景使用此选中状态:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_checked="true" android:drawable="@drawable/checked"/>
  <item android:drawable="@drawable/unchecked"/>
</selector>

这使得列表项视图的背景自动更改,而无需在每次选择列表项时在代码中手动更改。

<强>结果:

enter image description here

其他要点:

  1. 滚动条可以移动到左侧。
  2. 使用与阴影颜色匹配的列表分隔符,或者可以在列表项和详细视图之间放置更多填充。