Android constraintlayout 在约束图中从中心位置垂直偏移图像
我在屏幕上以图像为中心,如下所示:Android constraintlayout 在约束图中从中心位置垂直偏移图像,android-constraintlayout,Android Constraintlayout,我在屏幕上以图像为中心,如下所示: <androidx.constraintlayout.motion.widget.ConstraintLayout android:id="@+id/dashboardConstraintLayout" android:layout_width="match_parent" android:layout_height="match_parent"> <androidx.appcompat.widget.App
<androidx.constraintlayout.motion.widget.ConstraintLayout
android:id="@+id/dashboardConstraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/logo"
android:layout_width="155dp"
android:layout_height="20dp"
android:scaleType="centerCrop"
app:srcCompat="@drawable/ic_logo"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.motion.widget.ConstraintLayout>
我想做的是让图像从中心位置向下偏移50dp。添加marginTop不起作用。所做的只是在屏幕顶部添加一个边距,图像将被约束。图像仍保留在中间。但我想把它调低50分
我试过了,效果很好,我强调了我修改过的代码
我试过了,效果很好,我强调了我修改过的代码
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
tools:context=".Third">
<androidx.appcompat.widget.AppCompatImageView //it is normar imageView in centered
android:id="@+id/logo"
android:layout_width="155dp"
android:layout_height="20dp"
android:scaleType="centerCrop"
android:src="@drawable/ic_launcher_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<androidx.appcompat.widget.AppCompatImageView //in this imageView i used marginTop and it works perfectly
android:id="@+id/logo1"
android:layout_width="155dp"
android:layout_height="20dp"
android:scaleType="centerCrop"
android:src="@drawable/two"
android:layout_marginTop="50dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<androidx.appcompat.widget.AppCompatImageView //in this imageView i used vertical_bias and it work perfectly.
android:id="@+id/logo2"
android:layout_width="155dp"
android:layout_height="20dp"
android:scaleType="centerCrop"
android:src="@drawable/ic_launcher_background"
app:layout_constraintVertical_bias="0.60" //there is 0.0=Top, 0.50=center, 1.0=Bottom and so on.
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>