ScrollView不能用RelativeLayout的解决方案

简介:

RelativeLayout的意义:

   布局各个部件的相对布局。使得界面空间合理利用。

   

一、ScrollView局限:

  滑动的只能是linearlayout,甚至整个布局都不能有RelativeLayout。这使得让人觉得ScrollView控件有点鸡肋。其实不然..........

   linearlayout跟RelativeLayout布局在界面上来看只是空间间隔的区别,而在liearlayout中有一个<View/>能占用空间,单单用linearlayout要达到    RelativeLayout的效果,可以用<View/>来实现。


二、View用法

   <View

   android:layout_width="fill_parent"
       android:layout_height="10sp"

   />

三、例子

   下面的界面

   

1)用RelativeLayout实现非常容易实现

   RelativeLayout代码

   

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
< RelativeLayout  xmlns:android = "http://schemas.android.com/apk/res/android"
     xmlns:tools = "http://schemas.android.com/tools"
     android:layout_width = "match_parent"
     android:layout_height = "fill_parent"
     tools:context = ".ClientActivity"  >
     < ImageView
         android:id = "@+id/clientinfo_headpicture"
         android:layout_width = "90sp"
         android:layout_height = "90sp"
         android:background = "@drawable/client_pic_back"
         android:src = "@drawable/client_pic_src"  />
     < TextView
         android:id = "@+id/client_tel"
         android:layout_width = "match_parent"
         android:layout_height = "30sp"
         android:layout_alignBottom = "@+id/clientinfo_headpicture"
         android:layout_toRightOf = "@+id/clientinfo_heaspicture"
         android:background = "@color/black"
         android:ems = "12"
         android:singleLine = "true"
         android:text = "电话号码"
         android:textColor = "@color/white"  />
     < Button
         android:id = "@+id/client_tel_edit"
         android:layout_width = "50sp"
         android:layout_height = "30sp"
         android:layout_above = "@+id/client_tel"
         android:layout_alignParentRight = "true"
         android:background = "@drawable/cliebt_button_edittel"
         android:text = "编辑"
         android:textColor = "@color/blue"  />
     < TextView
         android:layout_width = "match_parent"
         android:layout_height = "30sp"
         android:layout_alignLeft = "@+id/client_tel"
         android:layout_alignParentTop = "true"
         android:background = "@color/black"
         android:singleLine = "true"
         android:text = "用户名"
         android:textColor = "@color/white"
         android:textSize = "24sp"  />
     < View
         android:id = "@+id/view1"
         android:layout_width = "fill_parent"
         android:layout_height = "10sp"
         android:layout_alignParentRight = "true"
         android:layout_below = "@+id/clientinfo_headpicture"
         android:background = "@color/blue"  />
     < RelativeLayout
         android:layout_width = "fill_parent"
         android:layout_height = "match_parent"
         android:layout_alignParentLeft = "true"
         android:layout_below = "@+id/view1"
         android:background = "@drawable/client_moreinfo_back"  >
         < Button
             android:id = "@+id/client_myaddress"
             android:layout_width = "50sp"
             android:layout_height = "30sp"
             android:background = "@drawable/client_address"  />
         < TextView
             android:id = "@+id/client_myaddress_text"
             android:layout_width = "wrap_content"
             android:layout_height = "30sp"
             android:layout_alignBaseline = "@+id/client_myaddress"
             android:layout_alignBottom = "@+id/client_myaddress"
             android:layout_toRightOf = "@+id/client_myaddress"
             android:text = "我的地址"
             android:textColor = "@color/blue"
             android:textSize = "24sp"  />
         < View
             android:id = "@+id/client_myaddress_div"
             android:layout_width = "fill_parent"
             android:layout_height = "1sp"
             android:layout_alignParentLeft = "true"
             android:layout_below = "@+id/client_myaddress"
             android:background = "@color/blue"  />
         < TextView
             android:id = "@+id/client_myaddress_addtext"
             android:layout_width = "160sp"
             android:layout_height = "50sp"
             android:layout_alignLeft = "@+id/client_myaddress_div"
             android:layout_below = "@+id/client_myaddress_div"
             android:layout_marginLeft = "14sp"
             android:text = "31栋127寝室电话18607060000"
             android:textColor = "@color/blue"  />
         < Button
             android:id = "@+id/client_myaddress_edit"
             android:layout_width = "40sp"
             android:layout_height = "40sp"
             android:layout_alignRight = "@+id/client_myaddress_div"
             android:layout_alignTop = "@+id/client_myaddress_addtext"
             android:background = "@drawable/client_edit"  />
         < View
             android:id = "@+id/client_buyhistory_div"
             android:layout_width = "fill_parent"
             android:layout_height = "5sp"
             android:layout_alignParentLeft = "true"
             android:layout_below = "@+id/client_myaddress_addtext"
             android:background = "@color/blue"  />
         < Button
             android:id = "@+id/client_buyhistory"
             android:layout_width = "50sp"
             android:layout_height = "30sp"
             android:layout_below = "@+id/client_buyhistory_div"
             android:layout_marginTop = "1sp"
             android:layout_toLeftOf = "@+id/client_myaddress_text"
             android:background = "@drawable/client_shopcar"  />
         < TextView
             android:id = "@+id/client_buyhistory_text"
             android:layout_width = "100sp"
             android:layout_height = "30sp"
             android:layout_alignRight = "@+id/client_myaddress_text"
             android:layout_alignTop = "@+id/client_buyhistory"
             android:text = "已购买"
             android:textColor = "@color/blue"
             android:textSize = "24sp"  />
         < View
             android:id = "@+id/client_buyhistory_div_div"
             android:layout_width = "fill_parent"
             android:layout_height = "1sp"
             android:layout_alignParentLeft = "true"
             android:layout_below = "@+id/client_buyhistory"
             android:background = "@color/blue"  />
         < TextView
             android:id = "@+id/client_buyhistory_info"
             android:layout_width = "160sp"
             android:layout_height = "30sp"
             android:layout_alignLeft = "@+id/client_buyhistory_div_div"
             android:layout_below = "@+id/client_buyhistory_div_div"
             android:text = "北京烤鸭100元"
             android:textColor = "@color/blue"  />
         < Button
             android:id = "@+id/client_buyhistory_eidt"
             android:layout_width = "40sp"
             android:layout_height = "40sp"
             android:layout_alignParentRight = "true"
             android:layout_centerVertical = "true"
             android:background = "@drawable/client_edit"  />
         < View
             android:id = "@+id/client_store_div"
             android:layout_width = "fill_parent"
             android:layout_height = "5sp"
             android:layout_alignParentRight = "true"
             android:layout_below = "@+id/client_buyhistory_eidt"
             android:background = "@color/blue"  />
         < Button
             android:id = "@+id/client_store"
             android:layout_width = "50sp"
             android:layout_height = "30sp"
             android:layout_alignParentLeft = "true"
             android:layout_below = "@+id/client_store_div"
             android:background = "@drawable/client_stored"  />
         < TextView
             android:id = "@+id/client_store_text"
             android:layout_width = "80sp"
             android:layout_height = "30sp"
             android:layout_alignBaseline = "@+id/client_store"
             android:layout_alignBottom = "@+id/client_store"
             android:layout_alignLeft = "@+id/client_myaddress_text"
             android:text = "收藏"
             android:textColor = "@color/blue"
             android:textSize = "24sp"  />
         < View
             android:id = "@+id/client_store_div_div"
             android:layout_width = "fill_parent"
             android:layout_height = "1sp"
             android:layout_alignParentLeft = "true"
             android:layout_below = "@+id/client_store"
             android:background = "@color/blue"  />
         < Button
             android:id = "@+id/client_store_edit"
             android:layout_width = "40sp"
             android:layout_height = "40sp"
             android:layout_alignParentRight = "true"
             android:layout_alignTop = "@+id/client_store_info"
             android:background = "@drawable/client_edit"  />
         < View
             android:id = "@+id/View01"
             android:layout_width = "fill_parent"
             android:layout_height = "5sp"
             android:layout_alignParentBottom = "true"
             android:layout_centerHorizontal = "true"
             android:background = "@color/blue"  />
         < TextView
             android:id = "@+id/client_store_info"
             android:layout_width = "160sp"
             android:layout_height = "40sp"
             android:layout_alignLeft = "@+id/View01"
             android:layout_below = "@+id/client_store_div_div"
             android:text = "北京烤鸭30元"
             android:textColor = "@color/blue"  />
     </ RelativeLayout >
</ RelativeLayout >



但因为有个项目用到的是TabHost,对子activity的布局有限制,上面的布局超过范围。所以要用到ScrollView,为达到上面的布局,要用到<View/>控件。

2)使用view控件的代码如下

   

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
< ScrollView  xmlns:android = "http://schemas.android.com/apk/res/android"
     xmlns:tools = "http://schemas.android.com/tools"
     android:layout_width = "wrap_content"
     android:layout_height = "wrap_content"
     android:fadingEdge = "vertical"
     android:scrollbars = "vertical"  >
                                                                                  
     < LinearLayout
         android:orientation = "vertical"
         android:layout_width = "fill_parent"
         android:layout_height = "match_parent"
         android:background = "@drawable/account_pic_back"
         >
         < TextView
         android:layout_width = "match_parent"
         android:layout_height = "30sp"
         android:background = "@color/black"
         android:singleLine = "true"
         android:text = "用户名"
         android:textColor = "@color/white"
         android:textSize = "24sp"  />
          < LinearLayout
         android:orientation = "horizontal"
         android:layout_width = "fill_parent"
         android:layout_height = "match_parent"
         android:background = "@drawable/account_pic_back"
         >
              < ImageView
         android:id = "@+id/clientinfo_headpicture"
         android:layout_width = "90sp"
         android:layout_height = "90sp"
         android:background = "@drawable/client_pic_back"
         android:src = "@drawable/client_pic_src"  />
               < Button
         android:id = "@+id/client_tel_edit"
         android:layout_width = "50sp"
         android:layout_height = "30sp"
         android:background = "@drawable/cliebt_button_edittel"
         android:text = "编辑"
         android:textColor = "@color/blue"  />
          </ LinearLayout >>
                                                                                    
     < TextView
         android:id = "@+id/client_tel"
         android:layout_width = "match_parent"
         android:layout_height = "30sp"
         android:background = "@color/black"
         android:ems = "12"
         android:singleLine = "true"
         android:text = "电话号码"
         android:textColor = "@color/white"  />
                                                                                 
     < View
         android:layout_width = "fill_parent"
         android:layout_height = "10sp"
         android:background = "@color/blue"  />
      < LinearLayout
         android:orientation = "horizontal"
         android:layout_width = "fill_parent"
         android:layout_height = "match_parent"
         android:background = "@drawable/account_pic_back"
         >
           < Button
             android:id = "@+id/client_myaddress"
             android:layout_width = "50sp"
             android:layout_height = "30sp"
             android:background = "@drawable/client_address"  />
         < TextView
             android:id = "@+id/client_myaddress_text"
             android:layout_width = "wrap_content"
             android:layout_height = "30sp"
             android:text = "我的地址"
             android:textColor = "@color/blue"
             android:textSize = "24sp"  />
      </ LinearLayout >
    < View
             android:layout_width = "fill_parent"
             android:layout_height = "1sp"
             android:background = "@color/blue"  />
                                                                                    
     < LinearLayout
         android:orientation = "horizontal"
         android:layout_width = "fill_parent"
         android:layout_height = "match_parent"
         android:background = "@drawable/account_pic_back"
         >
       < TextView
             android:id = "@+id/client_myaddress_addtext"
             android:layout_width = "160sp"
             android:layout_height = "50sp"
             android:layout_alignLeft = "@+id/client_myaddress_div"
             android:layout_below = "@+id/client_myaddress_div"
             android:layout_marginLeft = "14sp"
             android:text = "31栋127寝室电话18607060000"
             android:textColor = "@color/blue"  />
         < View
         android:layout_width = "100sp"
         android:layout_height = "40sp"
         />
                                                                                    
         < Button
             android:id = "@+id/client_myaddress_edit"
             android:layout_width = "40sp"
             android:layout_height = "40sp"
             android:background = "@drawable/client_edit"  />
         </ LinearLayout >
         < View
         android:layout_width = "fill_parent"
         android:layout_height = "10sp"
         android:background = "@color/blue"  />
           < LinearLayout
         android:orientation = "horizontal"
         android:layout_width = "fill_parent"
         android:layout_height = "match_parent"
         android:background = "@drawable/account_pic_back"
         >
         < Button
             android:id = "@+id/client_buyhistory"
             android:layout_width = "50sp"
             android:layout_height = "30sp"
             android:layout_marginTop = "1sp"
             android:background = "@drawable/client_shopcar"  />
         < TextView
             android:id = "@+id/client_buyhistory_text"
             android:layout_width = "100sp"
             android:layout_height = "30sp"
             android:text = "已购买"
             android:textColor = "@color/blue"
             android:textSize = "24sp"  />
         </ LinearLayout >
          < View
         android:id = "@+id/view1"
         android:layout_width = "fill_parent"
         android:layout_height = "1sp"
         android:background = "@color/blue"  />
           < LinearLayout
         android:orientation = "horizontal"
         android:layout_width = "fill_parent"
         android:layout_height = "match_parent"
         android:background = "@drawable/account_pic_back"
         >
          < TextView
             android:id = "@+id/client_buyhistory_info"
             android:layout_width = "160sp"
             android:layout_height = "30sp"
             android:text = "北京烤鸭100元"
             android:textColor = "@color/blue"  />
          < View
         android:layout_width = "100sp"
         android:layout_height = "40sp"
         />
                                                                                       
         < Button
             android:id = "@+id/client_buyhistory_eidt"
             android:layout_width = "40sp"
             android:layout_height = "40sp"
             android:background = "@drawable/client_edit"  />
           </ LinearLayout >
        < View
         android:layout_width = "fill_parent"
         android:layout_height = "1sp"
         android:background = "@color/blue"  />
                                                                                       
     < LinearLayout
         android:orientation = "horizontal"
         android:layout_width = "fill_parent"
         android:layout_height = "match_parent"
         android:background = "@drawable/account_pic_back"
         >
         < Button
             android:id = "@+id/client_store"
             android:layout_width = "50sp"
             android:layout_height = "30sp"
             android:background = "@drawable/client_stored"  />
         < TextView
             android:id = "@+id/client_store_text"
             android:layout_width = "80sp"
             android:layout_height = "30sp"
             android:text = "收藏"
             android:textColor = "@color/blue"
             android:textSize = "24sp"  />
         < View
             android:layout_width = "fill_parent"
             android:layout_height = "1sp"
             android:background = "@color/blue"  />
                                                                                      
     </ LinearLayout >    
        < LinearLayout
         android:orientation = "horizontal"
         android:layout_width = "fill_parent"
         android:layout_height = "match_parent"
         android:background = "@drawable/account_pic_back"
         >
     < TextView
             android:id = "@+id/client_store_info"
             android:layout_width = "160sp"
             android:layout_height = "40sp"
             android:text = "北京烤鸭30元"
             android:textColor = "@color/blue"  />
     < View
         android:layout_width = "100sp"
         android:layout_height = "40sp"
         />
     < Button
             android:id = "@+id/client_store_edit"
             android:layout_width = "40sp"
             android:layout_height = "40sp"
             android:background = "@drawable/client_edit"  />
     </ LinearLayout
     < View
             android:layout_width = "fill_parent"
             android:layout_height = "5sp"
             android:background = "@color/blue"  />
     </ LinearLayout >
                                                                                  
</ ScrollView >



通过View完美的调出RelativeLayout的效果


本文转自lilin9105 51CTO博客,原文链接:http://blog.51cto.com/7071976/1217017,如需转载请自行联系原作者

相关文章
|
Rust 安全 算法
【密码学】一文读懂BBS
之前聊过不少非密码学安全的伪随机数生成算法,这次呢,咱们来聊一个密码学安全的伪随机数生成器 「BBS」 ,这个是三位设计者的首字母: Blum、Blum 和 Shub。
1036 0
【密码学】一文读懂BBS
|
机器学习/深度学习 搜索推荐 算法
Learning Disentangled Representations for Recommendation | NIPS 2019 论文解读
近年来随着深度学习的发展,推荐系统大量使用用户行为数据来构建用户/商品表征,并以此来构建召回、排序、重排等推荐系统中的标准模块。普通算法得到的用户商品表征本身,并不具备可解释性,而往往只能提供用户-商品之间的attention分作为商品粒度的用户兴趣。我们在这篇文章中,想仅通过用户行为,学习到本身就具备一定可解释性的解离化的用户商品表征,并试图利用这样的商品表征完成单语义可控的推荐任务。
24150 0
Learning Disentangled Representations for Recommendation | NIPS 2019 论文解读
|
Java Unix Linux
Android Studio中Terminal运行./gradlew clean build提示错误信息
遇到 `./gradlew clean build`命令执行出错时,首先应检查错误信息的具体内容,这通常会指向问题的根源。从权限、环境配置、依赖下载、版本兼容性到项目配置本身,逐一排查并应用相应的解决措施。记住,保持耐心,逐步解决问题,往往复杂问题都是由简单原因引起的。
1139 2
|
JSON 自然语言处理 Java
Android App开发语音处理之系统自带的语音引擎、文字转语音、语音识别的讲解及实战(超详细 附源码)
Android App开发语音处理之系统自带的语音引擎、文字转语音、语音识别的讲解及实战(超详细 附源码)
2120 0
|
XML Android开发 数据安全/隐私保护
android 11后文件读写访问权限申请
android 11后文件读写访问权限申请
687 0
|
XML Android开发 数据格式
Android Studio 无法预览xml布局视图:failed to load AppCompat ActionBar with unkNown error
问题如下:   解决方法: 找到res-->values-->styles.xml 文件 可以看到主题Them设置如下:    修改为:   界面预览可以正常显示
7097 0
|
SQL 机器学习/深度学习 算法
2021年,算法工程师必备的能力是什么?
到底算法工程师需要具备什么样的能力?才能满足“越来越卷”的要求
|
人工智能 JSON JavaScript
AI Earth 开发者模式—— 如何加载影像?以Landsat 5 影像为例
AI Earth 开发者模式—— 如何加载影像?以Landsat 5 影像为例
759 1
AI Earth 开发者模式—— 如何加载影像?以Landsat 5 影像为例
|
Java 关系型数据库 数据库连接
快速配置多数据源(整合MyBatis)
本文内容: 在Springboot+Mybatis项目的基础上,学习多数据源的快速配置 避免网上某些配置数据源文章的深坑
591 0
|
SQL 关系型数据库 MySQL
探索MySQL-Cluster奥秘系列之SQL节点和数据节点配置(7)
上一小节中,我们讲解了MySQL-Cluster集群的管理节点的配置方法,在这一小节中,我们来学习下关于SQL节点和数据节点的配置方法。
705 0