[英]ScrollView doesn't work properly
I have two XML layout files, each has a ScrollView as parent. 我有两个XML布局文件,每个都有一个ScrollView作为父级。 While one is working properly, the other one doesn't (each XML has the same hierarchy).
当一个程序正常工作时,另一个程序却不能工作(每个XML具有相同的层次结构)。
activity_login.xml activity_login.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
android:fillViewport="true">
<android.support.constraint.ConstraintLayout
android:id="@+id/login_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tvLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/logo"
android:textSize="50sp"
app:layout_constraintBottom_toTopOf="@+id/guideline2"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.Guideline
android:id="@+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.25" />
<TextView
android:id="@+id/tvRegisterLabel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginStart="3dp"
android:text="@string/btn_login"
android:textSize="20sp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="@+id/guideline3"
app:layout_constraintRight_toLeftOf="@+id/guideline6"
app:layout_constraintTop_toTopOf="@+id/guideline2" />
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayout2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
app:layout_constraintLeft_toLeftOf="@+id/guideline3"
app:layout_constraintRight_toLeftOf="@+id/guideline6"
app:layout_constraintTop_toBottomOf="@+id/tvRegisterLabel">
<EditText
android:id="@+id/etEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/et_email_hint"
android:inputType="textEmailAddress"
android:maxLength="70"
android:maxLines="1"
android:minLines="1"
android:text="akarki@yahoo.com"
android:textSize="@dimen/et_hint_size" />
</android.support.design.widget.TextInputLayout>
<android.support.constraint.Guideline
android:id="@+id/guideline3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.15" />
<android.support.constraint.Guideline
android:id="@+id/guideline6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.85" />
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayout7"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="@+id/guideline3"
app:layout_constraintRight_toLeftOf="@+id/guideline6"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout2">
<EditText
android:id="@+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/et_password_hint"
android:inputType="textPassword"
android:maxLength="30"
android:maxLines="1"
android:minLines="1"
android:text="1234qwer"
android:textSize="@dimen/et_hint_size" />
</android.support.design.widget.TextInputLayout>
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:visibility="invisible"
app:layout_constraintLeft_toLeftOf="@+id/guideline3"
app:layout_constraintRight_toLeftOf="@+id/guideline6"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout7" />
<Button
android:id="@+id/btnLogIn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="@drawable/round_button"
android:text="@string/btn_login"
android:textColor="@color/colorWhite"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="@+id/guideline3"
app:layout_constraintRight_toLeftOf="@+id/guideline6"
app:layout_constraintTop_toBottomOf="@+id/progressBar" />
<com.facebook.login.widget.LoginButton
android:id="@+id/btnFacebook"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:paddingBottom="15dp"
android:paddingLeft="15dp"
android:paddingTop="15dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="@+id/guideline3"
app:layout_constraintRight_toLeftOf="@+id/guideline6"
app:layout_constraintTop_toBottomOf="@+id/btnLogIn" />
<ImageButton
android:id="@+id/btnGoogle"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginTop="8dp"
android:background="@drawable/google_round_button"
android:scaleType="centerInside"
android:src="@drawable/google_button_background"
app:layout_constraintLeft_toLeftOf="@+id/guideline3"
app:layout_constraintRight_toLeftOf="@+id/guideline6"
app:layout_constraintTop_toBottomOf="@+id/btnFacebook" />
<TextView
android:id="@+id/tvRegister"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:maxLines="2"
android:text="@string/tv_create_account"
android:textAlignment="center"
android:textColor="@color/colorPrimaryDark"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="@+id/guideline3"
app:layout_constraintRight_toLeftOf="@+id/guideline6"
app:layout_constraintTop_toBottomOf="@+id/tvForgotPassword" />
<TextView
android:id="@+id/tvForgotPassword"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/tv_forgot_password"
android:textAlignment="center"
android:textColor="@color/colorAccent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="@+id/guideline3"
app:layout_constraintRight_toLeftOf="@+id/guideline6"
app:layout_constraintTop_toBottomOf="@+id/btnGoogle" />
</android.support.constraint.ConstraintLayout>
activity_register activity_register
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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"
android:fillViewport="true">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.25" />
<android.support.constraint.Guideline
android:id="@+id/guideline4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.15" />
<android.support.constraint.Guideline
android:id="@+id/guideline5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.85" />
<TextView
android:id="@+id/tvLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/logo"
android:textSize="50sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/guideline"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tvRegisterLabel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="3dp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:layout_marginStart="3dp"
android:fontFamily="sans-serif"
android:text="@string/label_register"
android:textAllCaps="true"
android:textSize="20sp"
app:layout_constraintLeft_toLeftOf="@+id/guideline4"
app:layout_constraintRight_toRightOf="@+id/guideline5"
app:layout_constraintTop_toTopOf="@+id/guideline" />
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="@+id/guideline4"
app:layout_constraintRight_toRightOf="@+id/guideline5"
app:layout_constraintTop_toBottomOf="@+id/tvRegisterLabel">
<EditText
android:id="@+id/etEmailReg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:hint="@string/et_email_hint"
android:inputType="textEmailAddress"
android:maxLength="70"
android:maxLines="1"
android:minLines="1"
android:textSize="@dimen/et_hint_size" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayout3"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="@+id/guideline4"
app:layout_constraintRight_toRightOf="@+id/guideline5"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout">
<EditText
android:id="@+id/etNameReg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:hint="@string/et_name_hint"
android:inputType="textCapWords"
android:maxLength="30"
android:maxLines="1"
android:minLines="1"
android:textSize="@dimen/et_hint_size" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayout4"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="@+id/guideline4"
app:layout_constraintRight_toRightOf="@+id/guideline5"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout3">
<EditText
android:id="@+id/etPasswordReg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:hint="@string/et_password_hint"
android:inputType="textPassword"
android:maxLength="30"
android:maxLines="1"
android:minLines="1"
android:textSize="@dimen/et_hint_size" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayout5"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="@+id/guideline4"
app:layout_constraintRight_toRightOf="@+id/guideline5"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout4">
<EditText
android:id="@+id/etPasswordConfirmReg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:hint="@string/et_password_confirm_hint"
android:inputType="textPassword"
android:maxLength="30"
android:maxLines="1"
android:minLines="1"
android:textSize="@dimen/et_hint_size" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayout6"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="@+id/guideline4"
app:layout_constraintRight_toRightOf="@+id/guideline5"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout5">
<EditText
android:id="@+id/etPhoneNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:hint="@string/et_phone_hint"
android:inputType="phone"
android:maxLength="13"
android:maxLines="1"
android:minLines="1"
android:textSize="@dimen/et_hint_size" />
</android.support.design.widget.TextInputLayout>
<TextView
android:id="@+id/tvRequired"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/label_required"
android:textAlignment="textStart"
android:textSize="12sp"
app:layout_constraintLeft_toLeftOf="@+id/guideline4"
app:layout_constraintRight_toRightOf="@+id/guideline5"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout6" />
<Button
android:id="@+id/btnRegister"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:background="@drawable/round_button"
android:text="@string/label_register"
android:textColor="@android:color/white"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="@+id/guideline4"
app:layout_constraintRight_toRightOf="@+id/guideline5"
app:layout_constraintTop_toBottomOf="@+id/tvRequired" />
</android.support.constraint.ConstraintLayout>
So, to clarify my problem: In the activity_login the scrollview works correctly, as expected. 因此,为了澄清我的问题:在activity_login中 ,滚动视图按预期正常工作。 While in the activity_register the scrollview doesn't scroll to the bottom, I don't know why, because I've used the same hierarcy as in the activity_login .
而在activity_register滚动视图不滚动至底部,我不知道为什么,因为我已经使用了相同的hierarcy作为activity_login。
I've searched in SO for the same problem, but I haven't found any solution to my problem. 我已经在SO中搜索了相同的问题,但是我没有找到解决问题的方法。
Any help would be appreciated, I'm searching for a solution for days. 任何帮助将不胜感激,我正在寻找解决方案的日子。
I don't know for sure why it's a problem, but the problem seems to be your horizontal Guideline
. 我不确定为什么会出现问题,但问题似乎出在您的《横向
Guideline
。 If I delete the Guideline
, delete tvLogo
's reference to it, and change tvRegisterLabel
's reference to app:layout_constraintTop_toBottomOf="@+id/tvLogo"
, everything works. 如果删除
Guideline
,删除tvLogo
的引用,然后将tvRegisterLabel
对app:layout_constraintTop_toBottomOf="@+id/tvLogo"
的引用更改,则一切正常。
I suspect that it is because you seem to have a circular set of rules in your layout. 我怀疑这是因为您的布局中似乎有一套循环规则。 The
ConstraintLayout
's height is wrap_content
, so it has to lay out all of its views to know how big it is. ConstraintLayout
的高度为wrap_content
,因此必须布局所有视图才能知道它的大小。 To lay out its views, it must lay out tvLogo
. 要布置其视图,必须布置
tvLogo
。 To lay out tvLogo
, it must lay out guideline
. 要布置
tvLogo
,必须布置guideline
。 To lay out guideline
, the ConstraintLayout
must know how tall it is. 要制定
guideline
, ConstraintLayout
必须知道它有多高。 And so on. 等等。
By the way, it looks like you could perhaps just replace this ConstraintLayout
with a LinearLayout
. 顺便说一句,您似乎可以只用
LinearLayout
替换此ConstraintLayout
。
Sorry couldn't have much reputations to add comment so giving answer, 抱歉,没有什么好名声可以添加评论,因此给出答案,
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
remove padding
from this code in activity_register
xml, It will solve your problem 从
activity_register
xml中的此代码中删除padding
,它将解决您的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.