Android--UI之ScrollView
在Android Studio中设计UI,最开始只会用Constraint Layout,什么布局都是拖动和添加约束。
不会用density去适配各种手机,当自己的大屏幕手机上显示正常时,别的手机屏幕小可能就重叠了,比如
这时候,如果使用desity匹配所以的手机,那就不会出现这样的情况,但是项目一开始就没使用这个方法,那我们就用ScrollView使屏幕可以滚动,看了教程,很简单的使用也尝试了几次才成功。
这是原来的(内容已经删除了许多)
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="@string/fragment_tv_secondary_first_line"
android:textSize="15sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
只需要在最外面加上ScrollView的代码就可以,非常简单
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.constraint.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="@string/fragment_tv_secondary_first_line"
android:textSize="15sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</ScrollView>
这样就可以竖直滚动了,而水平滚动用HorizontalScrollView