使用边框排列Android Studio图像并将其置于右侧

r1zhe5dt  于 2022-12-13  发布在  Android
关注(0)|答案(1)|浏览(334)

我是Android开发的新手。我正在尝试创建一个基于此图像的布局。我如何管理对齐图像的边框和填充到边缘和定位到右边?非常感谢

mrphzbgm

mrphzbgm1#

它基于您使用的父视图。使用ConstraintLayout可以更容易地将图像与同级视图或父视图对齐。
当父视图为ConstraintLayout时,则可以使用以下属性:

  1. app:layout_constraintBottom_toBottomOf="viewId"
  2. app:layout_constraintEnd_toEndOf="viewId"
  3. app:layout_constraintStart_toStartOf="viewId"
  4. app:layout_constraintTop_toTopOf="viewId"
    您可以将您的视图与另一个id视图对齐,或者相对于您的parent视图对齐。
    此代码可能对您有所帮助。
<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=".MainActivity">

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="your_image_reference"
    app:layout_constraintEnd_toEndOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

相关问题