中心android滚动div至方框
我一直在胡闹,试图让我的登录框保持垂直居中,但由于某些原因,它不起作用。如果我将ConstraintLayout height更改为wrap_内容,则登录表单将居中,但背景图像也会向下挤压,如下所示: 背景图像应保持全屏,但由于主约束布局是包裹内容,因此会收缩其背景。如果我将其设置为“填充父对象”,则会发生以下情况。我们得到了一个全屏图像,但块也不再居中 我目前的结构如下:中心android滚动div至方框,android,layout,Android,Layout,我一直在胡闹,试图让我的登录框保持垂直居中,但由于某些原因,它不起作用。如果我将ConstraintLayout height更改为wrap_内容,则登录表单将居中,但背景图像也会向下挤压,如下所示: 背景图像应保持全屏,但由于主约束布局是包裹内容,因此会收缩其背景。如果我将其设置为“填充父对象”,则会发生以下情况。我们得到了一个全屏图像,但块也不再居中 我目前的结构如下: Constraint Layout -> Linear Layout -> Scroll View
Constraint Layout
-> Linear Layout
-> Scroll View
-> login form picture, fields, and button
我将它们全部设置为环绕,使用重力和布局将重力设置为中心,将重心设置为垂直,等等,但我仍然无法将此图像居中。有什么建议吗?以下是我的活动登录布局的当前XML
将此项添加到ConstraintLayout的子项应使子项水平和垂直居中:
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
还注意到:
填充父级在API级别8及更高版本中重命名为匹配父级 可能重复的
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"