滚动视图不适用于约束布局,所有内容都封装在我的手机屏幕中。我应该使用scrollview作为父布局吗?我的ScrollView布局的宽度应该是多少,我对wrap_content和match_parent感到困惑........................ ................................................... ....这就是我得到的
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#1a1a22"
tools:context="com.example.mrfrag.fullchargealarm.Settings">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollView6" android:fillViewport="true"
android:layout_marginTop="8dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
android:scrollbars = "vertical"
android:scrollbarStyle="insideInset"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintVertical_bias="0.0">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="FIRE1" />
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="FFIRE" />
<TextView
android:id="@+id/textVie2321"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="FFIRE" />
<TextView
android:id="@+id/textVie23"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="FFIRE" />
<TextView
android:id="@+id/textVie45"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="FFIRE" />
<TextView
android:id="@+id/tesadasdxtVie3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="FFIRE" />
<TextView
android:id="@+id/teasasdxtVie3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="FFIRE" />
<TextView
android:id="@+id/texasastVie3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="FFIRE" />
<TextView
android:id="@+id/textVsase3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="FFIRE" />
<TextView
android:id="@+id/textasdasdVsase3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="FFIRE" />
<TextView
android:id="@+id/tasdasdextVsase3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="FFIRE" />
<TextView
android:id="@+id/texastVsase3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="FFIRE" />
<TextView
android:id="@+id/texVsase3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="FFIRE" />
<TextView
android:id="@+id/tetVsase3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="FFIRE" />
</LinearLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>
要使其正常工作,请将ScrollView设置为父视图,其宽度和高度为match_parent
(因此它会填满整个屏幕)。然后将下一个布局放入其中,其宽度为match_parent
(因此是父项的宽度),高度为wrap_content
(因此它可以高于父项的高度,并滚动以显示内容)。
怎么wrap_content
办?它可以使视图达到显示其内容所需的高度。如果它比父母高,则可ScrollView
让您上下滚动以查看内容。
例如:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- this could be a constraint layout instead if you want -->
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- STUFF -->
</LinearLayout>
</ScrollView>
在您的情况下,不需要父ConstraintLayout,因为只有一个子视图并且它填充了父视图,但是如果您想保留自己的层次结构,只需将LinearLayout
里面的立即数更改ScrollView
为wrap_content
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句