本例使用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;">

更多相关文章

  1. Android(安卓)图片裁剪之三剑式(一)
  2. android 显示进度的按钮
  3. Android学习心得(五)——GOOGLE MAP
  4. ImageView显示图片时,上下出现多余空白。
  5. Android文本输入框EditText方法说明和属性
  6. 安卓模拟器Android(安卓)SDK Manager 无法获取SDK列表的解决办法
  7. Android自定义数字键盘解析
  8. ✿Android(安卓)3.1 --- 久违的 USB、mtp、rtp
  9. Android(安卓)Studio 3.5.2版本中Kotlin代码不显示代码补齐自动

随机推荐

  1. LinearLayout和RelativeLayout 属性对比
  2. RadioGroup和RadioButton的使用记录
  3. android 处理鼠标滚轮事件
  4. Android(安卓)SDK版本名和API level对照
  5. android :FTPServer
  6. android之实现各个组件点击事件处理
  7. RelativeLayout用到的一些重要的属性(自
  8. 安卓巴士Android开发神贴整理
  9. Android(安卓)微信分享,微信分享图片
  10. Android(安卓)Gradle 构建工具(Android(