2种方法

1是以xml为主:

View Code 1 <? xml version="1.0" encoding="utf-8" ?>
2 < LinearLayout android:orientation ="horizontal"
3 xmlns:android ="http://schemas.android.com/apk/res/android"
4 android:layout_width ="fill_parent" android:layout_height ="wrap_content" >
5 < TextView android:text ="这是滚动" android:textColor ="#f7b400"
6 android:background ="#603012" android:layout_width ="wrap_content"
7 android:layout_height ="30dip" ></ TextView >
8 < ScrollView android:id ="@+id/ScrollView01"
9 android:layout_width ="wrap_content" android:layout_height ="wrap_content"
10 xmlns:android ="http://schemas.android.com/apk/res/android" >
11 < HorizontalScrollView android:id ="@+id/HorizontalScrollView01"
12 android:layout_width ="fill_parent" android:layout_height ="fill_parent"
13 xmlns:android ="http://schemas.android.com/apk/res/android" >
14 < TableLayout android:id ="@+id/TableLayout01"
15 android:layout_width ="fill_parent" android:layout_height ="fill_parent"
16 android:stretchColumns ="0" android:background ="#603012"
17 xmlns:android ="http://schemas.android.com/apk/res/android" >
18 < TableRow android:layout_width ="fill_parent"
19 android:layout_height ="30dip" >
20 < Button android:text =" I am 001" android:textColor ="#f7b400"
21 android:layout_width ="fill_parent" android:layout_height ="fill_parent" >
22 </ Button >
23 < Button android:text =" I am 002" android:textColor ="#f7b400"
24 android:layout_width ="fill_parent" android:layout_height ="fill_parent" >
25 </ Button >
26 < Button android:text =" I am 003" android:textColor ="#f7b400"
27 android:layout_width ="fill_parent" android:layout_height ="fill_parent" >
28 </ Button >
29 < Button android:text =" I am 004" android:textColor ="#f7b400"
30 android:layout_width ="fill_parent" android:layout_height ="fill_parent" >
31 </ Button >
32 < Button android:text =" I am 005" android:textColor ="#f7b400"
33 android:layout_width ="fill_parent" android:layout_height ="fill_parent" >
34 </ Button >
35 < Button android:text =" I am 006" android:textColor ="#f7b400"
36 android:layout_width ="fill_parent" android:layout_height ="fill_parent" >
37 </ Button >
38 < Button android:text =" I am 007" android:textColor ="#f7b400"
39 android:layout_width ="fill_parent" android:layout_height ="fill_parent" >
40 </ Button >
41 </ TableRow >
42 </ TableLayout >
43 </ HorizontalScrollView >
44 </ ScrollView >
45 </ LinearLayout >

最外层是线性布局horizontal横向排列

第二层是2个:一个是textview另一个就是ScrollView(上下滚动)

而在ScrollView里面又套了一层HorizontalScrollView(左右滚动)

在这两层滚动里面的就是TableLayout

TableLayout里面是一个TableRow,在TableRow里面是7个button

基本上的布局完成。

如果我只要左右滚动而不要上下滚动怎么办?

试了下把ScrollView屏蔽只用HorizontalScrollView

结果报错Caused by: java.lang.ClassCastException: android.widget.ScrollView

原因是ScrollView是父控件如果没有它那么HorizontalScrollView是无法使用的。

这是个问题(暂留)

下面看看java代码部分:

View Code 1 package com.hsm.activity;
2
3
4 import android.app.Activity;
5 import android.os.Bundle;
6 import android.widget.HorizontalScrollView;
7 import android.widget.ScrollView;
8
9 public class FirstActivity extends Activity
10 {
11 private ScrollView mScrollView;
12 private HorizontalScrollView hScrollView;
13 /** Called when the activity is first created. */
14 @Override
15 public void onCreate(Bundle savedInstanceState)
16 {
17 super .onCreate(savedInstanceState);
18 setContentView(R.layout.main);
19 mScrollView = (ScrollView)findViewById(R.id.ScrollView01);
20 hScrollView = (HorizontalScrollView)findViewById(R.id.HorizontalScrollView01);
21 mScrollView.setVerticalScrollBarEnabled( false );
22 hScrollView.setHorizontalScrollBarEnabled( false );
23
24
25
26 }
27
28
29 }

这个也没有必要废话了~~主要的就是21,22行两行代码这两个的意思就是是否显示滚动条false不显示true显示

如果要在xml文件中设置是否隐藏滚动条

android:scrollbars="none"

由于只做了一行所以显示是这个样子,

如果做多行可以但是是需要手动添加,很明显是很麻烦的。。。。。看看能不能有好方法.

而且这样的布局远远达不到我的要求所以必须要更改哈哈

(未完待续卡卡)



更多相关文章

  1. AndroidStudio快捷键设置2
  2. 使用TensorFlow在Android上进行物体检测
  3. Android内部存储改变读取权限
  4. android调用照相机拍照获取照片并做简单剪裁
  5. 限制EditText输入文字的数目
  6. Android布局优化之TextView、ImageView合二为一
  7. Android中的GalleryView实例演示-周末福利有美女图
  8. ViewPager用法(一)图片+原点+循环播放
  9. RelativeLayout布局属性详解

随机推荐

  1. centos7下/etc/rc.local文件里配置的开机
  2. Centos7系统下修改主机名、清理linux日志
  3. Centos7.4安装kvm虚拟机(使用virt-manager
  4. Python中列表、元组、字典有何区别?Pytho
  5. Nextcloud私有云盘在Centos7下的部署笔记
  6. CentOS7 安装MySQL 5.7方法总结 - 实操手
  7. Nginx基于TCP/UDP端口的四层负载均衡(stre
  8. Oracle闪回恢复区(fast recovery area,FRA
  9. 【Linux】虚拟磁盘挂载错误,不能进入系统(f
  10. MySQL 的日期和时间函数