Android(安卓)ApiDemos示例解析(154):Views->Layouts->ScrollView->2. Long
16lz
2021-01-26
本例使用ScrollView显示一个长列表,其定义的scroll_view_2.xml
<ScrollView xmlns:android=”http://schemas.android.com/apk/res/android”android:layout_width=”match_parent”android:layout_height=”wrap_content”android:scrollbars=”none”><LinearLayoutandroid:id=”@+id/layout”android:orientation=”vertical”android:layout_width=”match_parent”android:layout_height=”wrap_content”><TextViewandroid:layout_width=”match_parent”android:layout_height=”wrap_content”android:text=”@string/scroll_view_2_text_1″/><Buttonandroid:layout_width=”match_parent”android:layout_height=”wrap_content”android:text=”@string/scroll_view_2_button_1″/></LinearLayout></ScrollView>
ScrollView 只定义了一个TextView 和 Button在LinearLayout中,而在ScrollView2.java 使用代码为LinearLayout 动态添加了63个TextView 和Button:
LinearLayout layout = (LinearLayout) findViewById(R.id.layout);for (int i = 2; i < 64; i++) { TextView textView = new TextView(this); textView.setText("Text View " + i); LinearLayout.LayoutParams p = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT ); layout.addView(textView, p); Button buttonView = new Button(this); buttonView.setText("Button " + i); layout.addView(buttonView, p);}
从而构成一个长列表,一屏肯定显示不下,此时就可以滚动屏幕来显示:
Layouts->ScrollView->2. Long_第1张图片" src="https://img.it610.com/image/info5/da3cf3ff91b94ac889bc2e65ba0e2926.jpg" width="650" height="463" style="font:inherit; margin:5px auto; padding:0px; border:currentColor; height:auto; vertical-align:baseline; display:block; max-width:100%;border:1px solid black;">
更多相关文章
- Android(安卓)图片裁剪之三剑式(一)
- android 显示进度的按钮
- Android学习心得(五)——GOOGLE MAP
- ImageView显示图片时,上下出现多余空白。
- Android文本输入框EditText方法说明和属性
- 安卓模拟器Android(安卓)SDK Manager 无法获取SDK列表的解决办法
- Android自定义数字键盘解析
- ✿Android(安卓)3.1 --- 久违的 USB、mtp、rtp
- Android(安卓)Studio 3.5.2版本中Kotlin代码不显示代码补齐自动