test.xml 布局文件,这个布局为GridView的每个项的布局。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
<!--?xml version=
1.0
encoding=utf-
8
?-->
<relativelayout android:layout_height=
"wrap_content"
android:layout_width=
"fill_parent"
android:orientation=
"vertical"
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<linearlayout android:gravity=
"center_vertical"
android:id=
"@+id/recommend_item_content_linear"
android:layout_height=
"wrap_content"
android:layout_width=
"fill_parent"
android:orientation=
"horizontal"
android:paddingbottom=
"5dp"
android:paddingtop=
"6dp"
>
<imageview android:contentdescription=
"@null"
android:id=
"@+id/recommend_item_icon"
android:layout_height=
"50dp"
android:layout_marginleft=
"2dp"
android:layout_width=
"50dp"
android:src=
"@drawable/icon"
>
<linearlayout android:gravity=
"center_vertical"
android:layout_height=
"wrap_content"
android:layout_marginleft=
"3dp"
android:layout_width=
"wrap_content"
android:orientation=
"vertical"
>
<textview android:id=
"@+id/recommend_item_appname"
android:layout_height=
"wrap_content"
android:layout_width=
"wrap_content"
android:text=
"测试文字"
android:textcolor=
"@color/black"
android:textsize=
"@dimen/text_size"
>
<linearlayout android:layout_height=
"wrap_content"
android:layout_width=
"wrap_content"
android:orientation=
"horizontal"
>
<textview android:id=
"@+id/recommend_item_intro"
android:layout_height=
"wrap_content"
android:layout_width=
"wrap_content"
android:text=
"体验"
android:textcolor=
"@color/dimgray"
android:textsize=
"@dimen/small_small_text_size"
>
<textview android:id=
"@+id/recommend_item_money"
android:layout_height=
"wrap_content"
android:layout_marginleft=
"2dp"
android:layout_width=
"wrap_content"
android:text=
"+4万5"
android:textcolor=
"@color/yellow_red"
android:textsize=
"@dimen/little_title_size"
>
</textview></textview></linearlayout>
</textview></linearlayout>
</imageview></linearlayout>
<view android:background=
"@drawable/custom_tab_indicator_divider"
android:contentdescription=
"@null"
android:id=
"@+id/recommend_item_bottomline"
android:layout_below=
"@+id/recommend_item_content_linear"
android:layout_height=
"1px"
android:layout_width=
"fill_parent"
>
<view android:background=
"@drawable/custom_tab_indicator_divider"
android:contentdescription=
"@null"
android:id=
"@+id/recommend_item_rightline"
android:layout_alignbottom=
"@+id/recommend_item_bottomline"
android:layout_alignparentright=
"true"
android:layout_height=
"fill_parent"
android:layout_width=
"1px"
>
</view></view></relativelayout>
|
<!--?xml version=1.0 encoding=utf-8?-->
<relativelayout android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">
<linearlayout android:gravity="center_vertical" android:id="@+id/recommend_item_content_linear" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="horizontal" android:paddingbottom="5dp" android:paddingtop="6dp">
<imageview android:contentdescription="@null" android:id="@+id/recommend_item_icon" android:layout_height="50dp" android:layout_marginleft="2dp" android:layout_width="50dp" android:src="@drawable/icon">
<linearlayout android:gravity="center_vertical" android:layout_height="wrap_content" android:layout_marginleft="3dp" android:layout_width="wrap_content" android:orientation="vertical">
<textview android:id="@+id/recommend_item_appname" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="测试文字" android:textcolor="@color/black" android:textsize="@dimen/text_size">
<linearlayout android:layout_height="wrap_content" android:layout_width="wrap_content" android:orientation="horizontal">
<textview android:id="@+id/recommend_item_intro" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="体验" android:textcolor="@color/dimgray" android:textsize="@dimen/small_small_text_size">
<textview android:id="@+id/recommend_item_money" android:layout_height="wrap_content" android:layout_marginleft="2dp" android:layout_width="wrap_content" android:text="+4万5" android:textcolor="@color/yellow_red" android:textsize="@dimen/little_title_size">
</textview></textview></linearlayout>
</textview></linearlayout>
</imageview></linearlayout>
<view android:background="@drawable/custom_tab_indicator_divider" android:contentdescription="@null" android:id="@+id/recommend_item_bottomline" android:layout_below="@+id/recommend_item_content_linear" android:layout_height="1px" android:layout_width="fill_parent">
<view android:background="@drawable/custom_tab_indicator_divider" android:contentdescription="@null" android:id="@+id/recommend_item_rightline" android:layout_alignbottom="@+id/recommend_item_bottomline" android:layout_alignparentright="true" android:layout_height="fill_parent" android:layout_width="1px">
</view></view></relativelayout>
GridView adapter (适配器)核心代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
@Override
public
View getView(
int
position, View convertView, ViewGroup parent) {
ViewHolder holder =
null
;
View row=convertView;
if
(convertView ==
null
) {
row=inflater.inflate(R.layout.recommend_item_layout,
null
);
holder =
new
ViewHolder();
holder.iconImageView=(ImageView)row.findViewById(R.id.recommend_item_icon);
holder.appNameTextView=(TextView)row.findViewById(R.id.recommend_item_appname);
holder.introTextView=(TextView)row.findViewById(R.id.recommend_item_intro);
holder.totalMoneyTextView=(TextView)row.findViewById(R.id.recommend_item_money);
holder.rightLineView=(View)row.findViewById(R.id.recommend_item_rightline);
row.setTag(holder);
}
else
{
holder=(ViewHolder)row.getTag();
}
String iconUrl=arrayList.get(position).getIconUrl();
String appName=arrayList.get(position).getAppName();
String intro=arrayList.get(position).getIntro();
String totalMoney=arrayList.get(position).getTotalMoney();
imageLoader.displayImage(iconUrl, holder.iconImageView);
holder.appNameTextView.setText(appName);
holder.introTextView.setText(intro);
if
(totalMoney!=
null
)
holder.totalMoneyTextView.setText(totalMoney);
else
holder.totalMoneyTextView.setText();
//单数就隐藏右边线,索引从0开始(双数开始)
if
(position%
2
!=
0
) {
holder.rightLineView.setVisibility(View.GONE);
}
return
row;
}
class
ViewHolder {
ImageView iconImageView;
TextView appNameTextView;
TextView introTextView;
TextView totalMoneyTextView;
View rightLineView;
}
|
我这里的边框线为纯色的,你可以使用渐变色实现更加绚丽的效果,诸如此类: