android 详细信息显示界面的思路

 开发的时候,有时候会遇到类似下面这种,需要显示大量数据的界面:

                                                             

        控件量很大,需要定义很多的textView 之类的东西,还需要用relativeLayout 来控制什么左对齐右对齐,这里有提供2种相对简便的方法。

 

方法1自定义一个控件,此控件包含一横条的布局;

定义一个叫TextTextView的控件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
< LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
     android:layout_width = "fill_parent" android:layout_height = "fill_parent"
     android:orientation = "horizontal" android:layout_marginTop = "3dip"
     android:layout_marginBottom = "3dip" >
     < TextView android:layout_marginLeft = "15dip" android:text = "TextView"
         android:id = "@+id/textViewIndex" android:layout_height = "wrap_content"
         android:layout_width = "fill_parent" android:layout_weight = "3"
         android:textColor = "@color/col_black" android:textSize = "14dip"
         android:gravity = "right|center" ></ TextView >
     < TextView android:layout_marginLeft = "15dip"
         android:layout_marginRight = "30dip" android:text = "TextView" android:id = "@+id/textViewValue"
         android:layout_height = "wrap_content" android:layout_width = "fill_parent"
         android:layout_weight = "2" android:textColor = "@color/col_blue"
         android:textSize = "14dip" android:gravity = "left|center" ></ TextView >
</ LinearLayout >


整体布局:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
< ScrollView android:layout_height = "wrap_content"
     android:layout_width = "fill_parent" android:id = "@+id/scrollViewView"
     android:layout_above = "@+id/relativeLayoutButton" android:layout_below = "@+id/linearLayoutTitle" >
     < LinearLayout android:layout_height = "wrap_content"
         android:layout_width = "fill_parent" android:id = "@+id/relativeLayout2"
         android:gravity = "left" android:layout_marginTop = "60dip"
         android:orientation = "vertical" >
         < TextTextItemView
             android:id = "@+id/itemviewCustid" android:layout_height = "wrap_content"
             android:layout_width = "fill_parent" />
         < TextTextItemView
             android:layout_height = "wrap_content" android:layout_width = "fill_parent"
             android:id = "@+id/itemviewItemname" />
         < TextTextItemView
             android:layout_height = "wrap_content" android:layout_width = "fill_parent" android:id = "@+id/itemviewReqcount" />
         < TextTextItemView
             android:layout_height = "wrap_content" android:layout_width = "fill_parent" android:id = "@+id/itemviewOrdercount" />
         < TextTextItemView
             android:layout_height = "wrap_content" android:layout_width = "fill_parent" android:id = "@+id/itemviewUnitprice" />
         < TextTextItemView
             android:layout_height = "wrap_content" android:layout_width = "fill_parent" android:id = "@+id/itemviewPrice" />
     </ LinearLayout >
</ ScrollView >


 

 

               这个方法的优点在于,方便让每一行都统一,如果需要修改,只需要修改这个控件里面的布局。

 

方法2:用listView来填充,把每一条作为一个listView的item;

 

写这么一个Item布局:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
< LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
     android:layout_width = "fill_parent" android:layout_height = "fill_parent"
     android:orientation = "horizontal" android:layout_marginTop = "3dip"
     android:layout_marginBottom = "3dip" >
     < TextView android:layout_marginLeft = "15dip" android:text = "TextView"
         android:id = "@+id/textViewIndex" android:layout_height = "wrap_content"
         android:layout_width = "fill_parent" android:layout_weight = "3"
         android:textColor = "@color/col_black" android:textSize = "14dip"
         android:gravity = "right|center" ></ TextView >
     < TextView android:layout_marginLeft = "15dip"
         android:layout_marginRight = "30dip" android:text = "TextView" android:id = "@+id/textViewValue"
         android:layout_height = "wrap_content" android:layout_width = "fill_parent"
         android:layout_weight = "2" android:textColor = "@color/col_blue"
         android:textSize = "14dip" android:gravity = "left|center" ></ TextView >
</ LinearLayout >


然后主界面一个listView:

1
2
3
4
5
6
7
8
9
10
< SPAN style = "FONT-SIZE: 13px" >< LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
     android:layout_width = "fill_parent" android:layout_height = "fill_parent"
     android:orientation = "horizontal" android:layout_marginTop = "3dip"
     android:layout_marginBottom = "3dip" >
     < ListView android:layout_marginLeft = "15dip" android:text = "TextView"
         android:id = "@+id/textViewIndex" android:layout_height = "wrap_content"
         android:layout_width = "fill_parent" android:layout_weight = "3"
         android:textColor = "@color/col_black" android:textSize = "14dip"
         android:gravity = "right|center" ></ ListView >
</ LinearLayout ></ SPAN >


 

然后代码里面建立一个list,把每一条的数据放进去:

1
2
<SPAN style= "FONT-SIZE: 13px" >ArrayList<HashMap<string , string>> mDetail= new ArrayList<HashMap<string , string>>;
mDetail.add( new HashMap( "abc" , "abc" ));</SPAN>

               这个方法的优点同上,而且还可以少定义XML,因为上面那个需要写一个一个的自定义控件,这个一个listView搞定。

               但是缺点在于代码里面要一直add,还要写adapter,而且listView的显示效果不是很好控制。

 

方法3:最原始的,一个一个摆控件

 

               这个方法的优点在于他最灵活,想怎么弄怎么弄

               缺点在于改起来实在太麻烦。。。。。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值