【发布时间】:2021-07-28 03:28:58
【问题描述】:
我需要在 ConstraintLayout 中将 ImageView 居中。问题是,因为它是一个 ScrollView,所以 ConstraintLayout 比屏幕高,也就是说,我无法限制 ImageView 的底部。我试图将 ImageView 和整个 ScrollView 放在另一个 ConstraintLayout 中,但这会与动画混淆(我将其转换为 MotionLayout)。有没有办法设置android:gravity="center" 或以某种方式参考屏幕高度(据我所知,不可能)?我是初学者,所以请放轻松。谢谢。
<?xml version="1.0" encoding="utf-8"?>
<!-- This ScrollView is taller than the screen. -->
<ScrollView 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:fillViewport="true"
android:fitsSystemWindows="true"
android:scrollbars="none">
<androidx.constraintlayout.motion.widget.MotionLayout
android:id="@+id/cl_permission"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/app_color_on_primary_dark"
app:layoutDescription="@xml/activity_permissions_scene"
tools:context=".Permissions">
<!-- How do I center this ImageView? -->
<ImageView
android:id="@+id/perm_logo"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginTop="60dp"
android:contentDescription="@string/perm_iv_camera_content_description"
android:src="@drawable/ic_antibody_splashscreen_face"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
.
.
.
【问题讨论】:
标签: android android-layout android-xml android-constraintlayout android-scrollview