Макет ограничения - Установите ширину ImageView 1/4 размера всего экрана - PullRequest
0 голосов
/ 03 марта 2020

Как бы я установить макет ImageView, чтобы он был 1/4 размера родительского макета, используя только XML. Я также хочу избегать использования LinearLayout, который вложен в родительский ConstraintLayout, чтобы сделать это.

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


       <ImageView
        android:id="@+id/fragprofile_profile_picture"
        android:layout_width="0dp"
        android:layout_height="75dp"/>


</androidx.constraintlayout.widget.ConstraintLayout>

Ответы [ 2 ]

1 голос
/ 03 марта 2020

Вы можете использовать GuideLine для этого,

<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">

    <android.support.constraint.Guideline
        android:id="@+id/guideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.25" />

    <ImageView
        android:id="@+id/fragprofile_profile_picture"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginTop="16dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@+id/guideline"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"/>

</android.support.constraint.ConstraintLayout>
1 голос
/ 03 марта 2020

Вы можете использовать Guideline.

Вертикальная направляющая.

<androidx.constraintlayout.widget.Guideline
        android:id="@+id/start_guide_line"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.25"
        />

Горизонтальная направляющая

<androidx.constraintlayout.widget.Guideline
        android:id="@+id/top_guide_line"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.25"
        />
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...