list_item.xml

1
<!--2
Copyright 2013 The Android Open Source Project3
4
Licensed under the Apache License, Version 2.0 (the "License");5
you may not use this file except in compliance with the License.6
You may obtain a copy of the License at7
8
http://www.apache.org/licenses/LICENSE-2.09
10
Unless required by applicable law or agreed to in writing, software11
distributed under the License is distributed on an "AS IS" BASIS,12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13
See the License for the specific language governing permissions and14
limitations under the License.15
-->16
17
<!--18
For list items that contain secondary actions (in this case, 'delete'),19
it's important to use dividers to distinguish the primary touch target from20
the secondary action. This is done using android:showDividers and its21
related attributes.22
23
The android:dividerPadding attribute insets the divider line by the given24
amount on each side (in this case, top and bottom). Divider padding helps25
establish visual hierarchy when several dividers are used in a screen. In26
this case, the padding helps separate this vertical divider from horizontal27
list item separators in the main ListView, and establishes a stronger28
relationship between the delete action and the primary target to its left.29
-->30
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"31
android:orientation="horizontal"32
android:layout_width="match_parent"33
android:layout_height="wrap_content"34
android:minHeight="?android:listPreferredItemHeight"35
android:divider="?android:dividerVertical"36
android:dividerPadding="8dp"37
android:showDividers="middle">38
39
<!--40
Any view or view group can become interactive by simply setting the41
android:clickable and android:focusable attributes to true.42
43
When doing this, make sure to provide adequate touch feedback by also44
setting the view background to ?android:selectableItemBackground. When45
using the Holo theme, this drawable is transparent by default, but46
changes to a translucent color overlay when the view is pressed or47
focused.48
-->49
<LinearLayout android:id="@+id/primary_target"50
android:layout_width="0dp"51
android:layout_height="match_parent"52
android:layout_weight="1"53
android:orientation="vertical"54
android:paddingLeft="?android:listPreferredItemPaddingLeft"55
android:paddingRight="?android:listPreferredItemPaddingRight"56
android:clickable="true"57
android:focusable="true"58
android:gravity="center_vertical"59
android:background="?android:selectableItemBackground">60
61
<TextView style="?android:textAppearanceListItemSmall"62
android:id="@android:id/text1"63
android:layout_width="wrap_content"64
android:layout_height="wrap_content"65
android:text="@string/dummy_title" />66
67
<TextView style="?android:textAppearanceSmall"68
android:id="@android:id/text2"69
android:layout_width="wrap_content"70
android:layout_height="wrap_content"71
android:text="@string/dummy_subtitle" />72
73
</LinearLayout>74
75
<!--76
When using the Holo theme, setting a Button or ImageButton to77
?android:borderlessButtonStyle removes its border and sets the78
background to ?android:selectableItemBackground, as described above.79
-->80
<ImageButton android:id="@+id/secondary_action"81
style="?android:borderlessButtonStyle"82
android:layout_width="@dimen/standard_touch_target_size"83
android:layout_height="match_parent"84
android:src="@drawable/ic_action_delete"85
android:contentDescription="@string/delete_content_description" />86
87
</LinearLayout>