Android Studio初学笔记-Day13-ScrollView

ScrollView

今天要介绍的元件,当介面的内容开始变多时就派上用场了,毕竟手机萤幕或着各类3c显示的大小都相当有限,在有大量内容或者制作类似电子书的样式时,可以透过ScrollView来制造滑动萤幕的效果,弥补萤幕不足的问题,使用方式也很简单,把需要滑动的内容放置ScrollView的标签之中即可,简单的示范配置如下。

程序码

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:layout_editor_absoluteX="159dp"
        tools:layout_editor_absoluteY="99dp"
        android:scrollbarStyle="insideInset">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:id="@+id/textView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="TextView介绍"
                android:textSize="30sp"
                android:textStyle="bold" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/textview"
                android:textSize="20sp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:id="@+id/EditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="EditView"
                android:textSize="30sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/textView3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/edittext"
                android:textSize="20sp" />
        </LinearLayout>
    </ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>

这里介绍一下ScrollView的属性
android:scrollbarStyle 此属性是设定滑动的样式,包括以下四种:

  1. insideOverlay(预设值)
  2. insideInset
  3. outsideOverlay
  4. outsideInset
    各位可以依序设定看看不一样的效果,或者不想要有滑动条的显示则可以设定android:scrollbars="none"。
    效果如下:
    https://ithelp.ithome.com.tw/upload/images/20210907/20139136oWFf3B1EEi.png
    这里要补充一下,ScrollView还有一个兄弟名叫HorizontalScrollView,从名字可以想像的到它的功能就是横向的ScrollView,而在用法上也可以说是相同的,所以这里就不再多做呈现,有兴趣的朋友可以当作熟悉ScrollView的用法来再玩一遍尝试看看喔。
    今天的ScrollView就讲到这里了,谢谢大家!/images/emoticon/emoticon41.gif

<<:  [Day 13] 阿嬷都看得懂的基础 CSS 选择器

>>:  [Tableau Public] day 28:制作台湾姓氏分布-数据仪表板

【Day21】:客制化的PWM输出

客制化PWM 这里所说的客制化PWM指的就是我们可以输出任何想要的方波波形,例如输出10个完整的波後...

[Day 27] 应用二:口罩下的人脸

前几天在谈到人脸识别有提到:大部分使用神经网路的模型都可以侦测与识别口罩下的人脸。 纳今天如果我们只...

Day12 - 409. Longest Palindrome

今日题目:409. Longest Palindrome Given a string s whic...

[2020铁人赛Day28]糊里糊涂Python就上手-Pandas的观念与运用(上)

今日目标 学习了解 Python Pandas 的观念与运用 What is Pandas? Pan...

【Day8】千算万算的运算子

运算子算是比较繁杂的部分,需要多些耐心来理解与记忆,没办法用一个简明的观念来一以贯之。 算术运算子...