android组件之ScrollView
来源:互联网 发布:c#管理系统界面源码 编辑:程序博客网 时间:2024/05/01 21:52
由于屏幕的高度有限,面对组件显示多组信息时,我们就可以使用scrollview有效的安排组件,浏览时通过滚屏显示,scrollview是FrameLayout 的子类,所以只是提供一个显示的容器。
使用过程中要注意以下两点 1.scrollview只是提供一个显示的容器,可以包含多个组件进行滚屏;2.scrollview只能包含一种组件,下面通过实例讲解:
1.scrollview的视图定义格式,必须在Scrollview中内嵌一个线性布局,组件的添加通过activity添加
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:id="@+id/mylayout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity" > </LinearLayout></ScrollView>
2.通过activity添加组件
public class MainActivity extends Activity {private String[] data= new String[20];@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);super.setContentView(R.layout.activity_main); // 调用默认的布局管理器LinearLayout layout = (LinearLayout) super.findViewById(R.id.mylayout); // 取得组件LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT); // 定义布局参数for (int x = 0; x < this.data.length; x++) { // 通过循环方式将以上的信息通过Button组件进行封装data[x]="item"+x;Button but = new Button(this);but.setText(this.data[x]); // 设置显示文字layout.addView(but, param); // 增加组件}}}
效果图如下:
- android组件之ScrollView
- Android Widget组件ScrollView
- android之ScrollView
- android控件之ScrollView
- Android 之ScrollView
- Android 笔记之ScrollView
- Android UI之ScrollView
- Android之ScrollView
- Android散打之ScrollView
- Android-UI之ScrollView
- Android之ScrollView
- Android--UI之ScrollView
- React Native控件之ScrollView组件详解
- Android组件之使用ScrollView实现屏幕滚动【防止屏幕不够用】
- Android组件 滚动条(ScrollView)
- Android 高级组件ScrollView和ViewPager
- ScrollView组件
- scrollview组件
- 专业学习成果
- B - 又见LKity(kmp)
- 机房收费系统(2)——组合查询
- 杂感
- OCP-1Z0-053-V12.02-603题
- android组件之ScrollView
- Deep learning with word2vec and gensim
- 从程序员到项目经理(1)
- sublime Text2 编辑器实用技巧
- 并查集-POJ2912 Rochambeau
- 方法重建Overload和方法的重写Overriding的区别
- Oracle Clusterware的心跳
- gstreamer summary
- 机房收费系统(3)——sql注入