ScrollView控件只是支持垂直滚动,而且在ScrollView中只能包含一个控件,通常是在<ScroolView>标签中定义了一个<LinearLayout>。

    标签并且在<LinearLayout>标签中android:orientation属性值设置为vertical,然后在<LinearLayout>标签中放置多个控件,如果<LinearLayout>标签中的控件所占用的总高度超出屏幕的高度,就会在屏幕的右侧出现一个滚动条。

一、建立工程,如图

ScrollView垂直滚动控件的使用ScrollView垂直滚动控件的使用

二、main.xml中代码

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:andro>
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
        <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="30dp"
            android:text="滚动视图"
            />
        <ImageView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/item1"
            />
        <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="30dp"
            android:text="显示多张图片"
            />
        <ImageView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/item2"
            />
        <ImageView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/item3"
            />
        <ImageView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/item4"
            />
        <ImageView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/item5"
            />
        
    </LinearLayout>
    

</ScrollView>
View Code

相关文章:

  • 2021-08-25
  • 2022-12-23
  • 2022-12-23
  • 2021-06-11
  • 2021-06-09
  • 2021-08-05
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-26
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案