Day 24 - Android Studio ScrollView的基本使用
昨天我们写了一篇实作程序,不知道大家有没有学起来,今天我们要再增加我们的程序工具,今天我们要讲的是Android Studio里面ScrollView的基本使用。
我们在平常用程序的时候,常常会遇到内容超出页面大小,因此有可以滚动的页面,通常这种就页面里面就会有ScrollView,通常,垂直滚动就是ScrollView,而水平移动就是HorizontalScrollView,今天我主要会强调在ScrollView,两者其实并没有什麽差别,只差在方向而已。
先新增一个ScrollView到我们的Design里面,ScrollView需要超过页面大小才可以进行滑动,所以我们就拉一个TextView包在我们的ScrollView里,并用回圈不断写入的方式,撑爆我们的TextView,这样我们就可以进行滑动了
xml程序码:
<ScrollView
android:id="@+id/scrollView2"
android:layout_height="match_parent"
android:layout_width="fill_parent"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
tools:ignore="HardcodedText,SpeakableTextPresentCheck">
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="30sp" />
</ScrollView>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="156dp"
android:layout_marginTop="528dp"
android:onClick="main"
android:text="@string/button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
主程序:
package com.example.myapplication
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.TextView
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
fun main(view: View){
var textView:TextView = findViewById(R.id.textView3)
for(i in 1..100){
textView.append("撑爆/")
}
}
}
我们就直接运行我们的程序吧!
在我们按下按钮後,就出现能够让我们滑动的页面啦!
明天我可能会讲比较重点的,我会讲Socket的实际应用,这有可能会沾到一点Python,或者我会继续讲Android Studio的其他新工具。
>>: [Day16] Webpack - AssetModules、DevServer
接下来要实作跳转之後的activty连接着viewpager跟tabitem去对应到相对的fragm...
Photo on charlesproxy.com 前言 Charles 是...
从左侧栏位获取药局位置 当我们在左设拦点击药局列表时,左侧的地图区域不会带我们到对应的位置,此时我们...
参考文件 https://kubernetes.io/docs/tasks/network/cust...
接下来要进到关於撰写程序上的概念学习,这一部分对於接下来要撰写比较长的程序时会非常重要!这边会先简单...