greendroid thumbnailitemview使用

1 public class VolumeTV extends Activity{
2     
3     @Override
4     public void onCreate(Bundle savedInstanceState) {
5         super.onCreate(savedInstanceState);
6         setContentView(R.layout.volume_tv);
7     }
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:greendroid="http://schemas.android.com/apk/res/com.example.contextawaredemo2"
 4     android:layout_width="wrap_content"
 5     android:layout_height="wrap_content"
 6     android:orientation="vertical" >
 7     
 8     <greendroid.widget.itemview.SeparatorItemView
 9     xmlns:android="http://schemas.android.com/apk/res/android"
10     style="?attr/gdSeparatorItemViewStyle"
11     android:id="@id/gd_separator_text"
12     android:layout_width="fill_parent"
13     android:layout_height="wrap_content"
14     android:minHeight="?attr/gdSeparatorItemViewPreferredHeight"
15     android:text="SETTING"
16     
17     android:gravity="center_vertical" />
18     
19     <greendroid.widget.itemview.ThumbnailItemView
20     xmlns:android="http://schemas.android.com/apk/res/android"
21     style="?attr/gdThumbnailItemViewStyle"
22     android:layout_height="wrap_content"
23     android:minHeight="?attr/gdItemViewPreferredHeight"
24     android:paddingLeft="?attr/gdItemViewPreferredPaddingLeft">
25     
26     <greendroid.widget.AsyncImageView
27         android:id="@id/gd_thumbnail"
28         style="?attr/gdThumbnailItemViewStyleThumbnail"
29         android:layout_height="?attr/gdItemViewPreferredHeight"
30         android:scaleType="centerInside"
31         android:src="@drawable/class1"
32         greendroid:defaultSrc="@drawable/class1" />
33 
34     <TextView
35         android:id="@id/gd_text"
36         style="?attr/gdThumbnailItemViewStyleText"
37         android:layout_width="fill_parent"
38         android:layout_toRightOf="@id/gd_thumbnail"
39         android:ellipsize="end"
40         android:gravity="bottom"
41         android:singleLine="true"
42         android:text="text" />
43 
44     <TextView
45         android:id="@id/gd_subtitle"
46         style="?attr/gdThumbnailItemViewStyleSubtitle"
47         android:layout_width="fill_parent"
48         android:layout_alignLeft="@id/gd_text"
49         android:layout_alignParentBottom="true"
50         android:layout_below="@id/gd_text"
51         android:layout_toRightOf="@id/gd_thumbnail"
52         android:ellipsize="end"
53         android:gravity="top"
54         android:singleLine="true"
55         android:text="subtext" />
56 
57 </greendroid.widget.itemview.ThumbnailItemView>
58 
59     <greendroid.widget.itemview.DescriptionItemView
60     xmlns:android="http://schemas.android.com/apk/res/android"
61     style="?attr/gdDescriptionItemViewStyle"
62     android:id="@id/gd_description"
63     android:layout_height="wrap_content"
64     android:minHeight="?attr/gdItemViewPreferredHeight"
65     android:paddingLeft="?attr/gdItemViewPreferredPaddingLeft"
66     android:text="After connect to TV, call to mobile will lead volumne of TV changed."
67 
68     android:gravity="center_vertical" />

 这样的话在第一行的separator之后会有thumbnailItem (在左边) 以及 checkbox(在右边) 最后有descriptionItem 但是上面的代码还是存在一点小问题

1.thumbnail没有出现

这是因为thumbnail 的第二个textview的属性设置有问题导致拉长到铺满整个页面,把description挤出去了

2.checkbox 没有到理想的最右边

这里需要用到alignParentRight 所以相应修改relativeLayout

下面是修正后的版本

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:greendroid="http://schemas.android.com/apk/res/com.example.contextawaredemo2"
 3     android:layout_width="fill_parent"
 4     android:layout_height="wrap_content"
 5     android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">
 6 
 7     <greendroid.widget.itemview.SeparatorItemView
 8         xmlns:android="http://schemas.android.com/apk/res/android"
 9         android:id="@id/gd_separator_text"
10         style="?attr/gdSeparatorItemViewStyle"
11         android:layout_width="fill_parent"
12         android:layout_height="wrap_content"
13         android:gravity="center_vertical"
14         android:minHeight="?attr/gdSeparatorItemViewPreferredHeight"
15         android:text="SETTING" />
16 
17     <RelativeLayout
18         android:layout_width="wrap_content"
19         android:layout_height="wrap_content"      
20         >
21 
22         <greendroid.widget.itemview.ThumbnailItemView
23             xmlns:android="http://schemas.android.com/apk/res/android"
24             style="?attr/gdThumbnailItemViewStyle"
25             android:layout_height="wrap_content"
26             android:layout_alignParentLeft="true"
27             android:paddingLeft="?attr/gdItemViewPreferredPaddingLeft"
28             >
29 
30             <greendroid.widget.AsyncImageView
31                 android:id="@id/gd_thumbnail"
32                 style="?attr/gdThumbnailItemViewStyleThumbnail"
33                 android:layout_height="wrap_content"
34 
35                 android:scaleType="centerInside"
36                 android:src="@drawable/class1"
37                 greendroid:defaultSrc="@drawable/class1" />
38 
39             <TextView
40                 android:id="@id/gd_text"
41                 style="?attr/gdThumbnailItemViewStyleText"
42                 android:layout_width="wrap_content"
43                 android:layout_height="wrap_content"
44                 android:layout_toRightOf="@id/gd_thumbnail"
45                 android:ellipsize="end"
46                 android:gravity="bottom"
47                 android:singleLine="true"
48                 android:text="@string/volume_tv"
49                  />
50 
51             <TextView
52                 android:id="@id/gd_subtitle"
53                 style="?attr/gdThumbnailItemViewStyleSubtitle"
54                 android:layout_width="wrap_content"
55                 android:layout_height="wrap_content"
56                 android:layout_below="@id/gd_text"
57                 android:layout_toRightOf="@id/gd_thumbnail"
58                 android:ellipsize="end"
59                 android:gravity="top"
60                 android:singleLine="true"
61                 android:text="@string/mobile_n_tv" 
62                 />
63         </greendroid.widget.itemview.ThumbnailItemView>
64 
65         <CheckBox
66             android:id="@+id/checkbox"
67             android:layout_width="wrap_content"
68             android:layout_height="wrap_content"
69             
70             android:gravity="right"
71             android:layout_alignParentRight="true">
72 
73 
74         </CheckBox>
75     </RelativeLayout>
76 
77     <greendroid.widget.itemview.DescriptionItemView
78         xmlns:android="http://schemas.android.com/apk/res/android"
79         android:id="@id/gd_description"
80         style="?attr/gdDescriptionItemViewStyle"
81         android:layout_width="fill_parent"
82         android:layout_height="wrap_content"
83         android:gravity="center_vertical"
84         android:minHeight="?attr/gdItemViewPreferredHeight"
85         android:paddingLeft="?attr/gdItemViewPreferredPaddingLeft"
86         android:text="After connect to TV, call to mobile will lead volumne of TV changed." />
87 
88     
89 
90 </LinearLayout>

 如果在这个基础上再加上action bar

  1 <?xml version="1.0" encoding="utf-8"?>
  2 
  3 <LinearLayout xmlns:greendroid="http://schemas.android.com/apk/res/com.example.contextawaredemo2"
  4     android:layout_width="fill_parent"
  5     android:layout_height="wrap_content"
  6     android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">
  7     <greendroid.widget.ActionBarHost
  8     xmlns:android="http://schemas.android.com/apk/res/android"
  9     android:id="@id/gd_action_bar_host"
 10     android:layout_width="fill_parent"
 11     android:layout_height="fill_parent"
 12     android:orientation="vertical">
 13     <greendroid.widget.ActionBar
 14         android:id="@id/gd_action_bar"
 15         android:layout_height="@dimen/gd_action_bar_height"
 16         android:layout_width="fill_parent"
 17         android:background="?attr/gdActionBarBackground"/>
 18     <FrameLayout
 19         android:id="@id/gd_action_bar_content_view"
 20         android:layout_height="0dp"
 21         android:layout_width="fill_parent"
 22         >
 23         <ListView
 24             android:layout_height="fill_parent"
 25             android:id="@android:id/list"
 26             android:layout_weight="1"
 27             android:layout_width="fill_parent"
 28             >
 29             
 30         </ListView>
 31     </FrameLayout>
 32     </greendroid.widget.ActionBarHost>
 33 
 34     <greendroid.widget.itemview.SeparatorItemView
 35         xmlns:android="http://schemas.android.com/apk/res/android"
 36         android:id="@id/gd_separator_text"
 37         style="?attr/gdSeparatorItemViewStyle"
 38         android:layout_width="fill_parent"
 39         android:layout_height="wrap_content"
 40         android:gravity="center_vertical"
 41         android:minHeight="?attr/gdSeparatorItemViewPreferredHeight"
 42         android:text="SETTING" />
 43 
 44     <RelativeLayout
 45         android:layout_width="wrap_content"
 46         android:layout_height="wrap_content"      
 47         >
 48 
 49         <greendroid.widget.itemview.ThumbnailItemView
 50             xmlns:android="http://schemas.android.com/apk/res/android"
 51             style="?attr/gdThumbnailItemViewStyle"
 52             android:layout_height="wrap_content"
 53             android:layout_alignParentLeft="true"
 54             android:paddingLeft="?attr/gdItemViewPreferredPaddingLeft"
 55             >
 56 
 57             <greendroid.widget.AsyncImageView
 58                 android:id="@id/gd_thumbnail"
 59                 style="?attr/gdThumbnailItemViewStyleThumbnail"
 60                 android:layout_height="wrap_content"
 61 
 62                 android:scaleType="centerInside"
 63                 android:src="@drawable/class1"
 64                 greendroid:defaultSrc="@drawable/class1" />
 65 
 66             <TextView
 67                 android:id="@id/gd_text"
 68                 style="?attr/gdThumbnailItemViewStyleText"
 69                 android:layout_width="wrap_content"
 70                 android:layout_height="wrap_content"
 71                 android:layout_toRightOf="@id/gd_thumbnail"
 72                 android:ellipsize="end"
 73                 android:gravity="bottom"
 74                 android:singleLine="true"
 75                 android:text="@string/volume_tv"
 76                  />
 77 
 78             <TextView
 79                 android:id="@id/gd_subtitle"
 80                 style="?attr/gdThumbnailItemViewStyleSubtitle"
 81                 android:layout_width="wrap_content"
 82                 android:layout_height="wrap_content"
 83                 android:layout_below="@id/gd_text"
 84                 android:layout_toRightOf="@id/gd_thumbnail"
 85                 android:ellipsize="end"
 86                 android:gravity="top"
 87                 android:singleLine="true"
 88                 android:text="@string/mobile_n_tv" 
 89                 />
 90         </greendroid.widget.itemview.ThumbnailItemView>
 91 
 92         <CheckBox
 93             android:id="@+id/checkbox"
 94             android:layout_width="wrap_content"
 95             android:layout_height="wrap_content"
 96             
 97             android:gravity="right"
 98             android:layout_alignParentRight="true">
 99 
100 
101         </CheckBox>
102     </RelativeLayout>
103 
104     <greendroid.widget.itemview.DescriptionItemView
105         xmlns:android="http://schemas.android.com/apk/res/android"
106         android:id="@id/gd_description"
107         style="?attr/gdDescriptionItemViewStyle"
108         android:layout_width="fill_parent"
109         android:layout_height="wrap_content"
110         android:gravity="center_vertical"
111         android:minHeight="?attr/gdItemViewPreferredHeight"
112         android:paddingLeft="?attr/gdItemViewPreferredPaddingLeft"
113         android:text="After connect to TV, call to mobile will lead volumne of TV changed." />
114 
115     
116 
117 </LinearLayout>
原文地址:https://www.cnblogs.com/lauraxia/p/2983141.html