控件量很大,需要定义很多的textView 之类的东西,还需要用relativeLayout 来控制什么左对齐右对齐,这里有提供2种相对简便的方法。
方法1:自定义一个控件,此控件包含一横条的布局;
定义一个叫TextTextView的控件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
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
|
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:最原始的,一个一个摆控件
这个方法的优点在于他最灵活,想怎么弄怎么弄
缺点在于改起来实在太麻烦。。。。。