【发布时间】:2015-08-08 22:22:42
【问题描述】:
我有一个动态列表视图:
<ListView android:layout_width="match_parent"
android:layout_height="match_parent"
android:fastScrollEnabled="true"
android:choiceMode="singleChoice"
android:dividerHeight="1dp"
android:divider="#1f000000"
android:background="@android:color/background_light"
android:drawSelectorOnTop="true"/>
带单元格:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/list_ripple">
有波纹:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/list_selected" android:state_activated="true"/>
</selector>
这很好用。
我的问题在我正在创建的另一个列表中。它是一个静态列表,所以我只是使用 TableLayout 和 TableRow 在 xml 中定义列表。有没有一种方法可以让我显示相同的“选定”状态。还有要显示的涟漪?
<TableLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="0">
<TableRow android:id="@+id/about_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:paddingLeft="16dp"
android:paddingBottom="20dp"
android:clickable="true"
android:background="@drawable/list_ripple">
我尝试将波纹放在背景元素上,但没有奏效。同样,最好的情况是获得灰色选择状态,表明表格行已被选中,如果可能的话,会出现波纹。
【问题讨论】:
-
到目前为止我发现的最好的方法是使用 ListView 并实现 BaseAdapter 来设置我想要的静态行样式。那时我得到列表视图涟漪和活动行为。
标签: android android-listview android-tablelayout