我在约束布局中设置ImageView的上边距时遇到问题。这是我的代码。
<?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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.roadrez.AuthActivity"
tools:showIn="@layout/activity_auth">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/mt_layout_padding"
android:paddingRight="@dimen/mt_layout_padding"
android:scrollbars="vertical">
<ImageView
android:id="@+id/login_logo"
android:layout_width="96dp"
android:layout_height="96dp"
android:layout_marginTop="100dp"
android:src="@drawable/logo"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</android.support.constraint.ConstraintLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>
答案 0 :(得分:0)
top_to_top_of约束缺失,这就是未设置margin / padding的原因。
<ImageView
android:id="@+id/login_logo"
android:layout_width="96dp"
android:layout_height="96dp"
android:layout_marginTop="100dp"
android:src="@drawable/logo"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />