Как разместить два вида внутри макета в одинаковом соотношении размеров и размеров? - PullRequest
0 голосов
/ 23 мая 2018

Я хочу разместить эти две части внутри макета, чтобы сформировать полосу загрузки.

wood board
и
loading indicator

Оранжевый индикатор должен бытьвнутри доски, но я не могу найти способ их правильно соединить ...

Окончательные результаты должны выглядеть следующим образом
this.

XMLФайл:

<android.support.constraint.ConstraintLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 android:layout_width="match_parent"
 android:layout_height="match_parent">

    <ImageView
        android:id="@+id/wood_board"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <com.menwithandroid.myhookah.gui.LoadingProgressBar
       android:id="@+id/loading_indicator"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content" />

</android.support.constraint.ConstraintLayout>

Как правильно подключить эти детали?Благодаря.

Ответы [ 4 ]

0 голосов
/ 24 мая 2018

Спасибо всем ...

Я использовал android.support.constraint.Guideline с app:layout_constraintGuide_percent, чтобы определить расположение индикатора внутри доски по процентам (для совместимости с различными размерами экрана).

Это выглядит как это

0 голосов
/ 23 мая 2018

Попробуйте с RelativeLayout что-то вроде этого:

    <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center">

           <ImageView
            android:id="@+id/wood_board"
            android:gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <com.menwithandroid.myhookah.gui.LoadingProgressBar
           android:id="@+id/loading_indicator"
            android:gravity="center"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content" />


 </RelativeLayout>

И затем соответственно установите размер ImageView, который будет соответствовать LoadingProgressBar

0 голосов
/ 23 мая 2018

с макетами ограничений очень просто ... вы можете размещать элементы в одной и той же точной позиции, и использовать android: elevation, чтобы один компонент перекрывал другой.

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
    android:id="@+id/wood_board"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_marginStart="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginBottom="8dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:src="@drawable/loading"
    android:elevation="2dp"/>

<ImageView
    android:id="@+id/loading_indicator"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginBottom="8dp"
    android:src="@drawable/bar"
    app:layout_constraintBottom_toBottomOf="@+id/wood_board"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="@+id/wood_board" />

Ваше решение будет выглядеть примерно так: здесь

0 голосов
/ 23 мая 2018

Это просто просмотр изображений внутри imageview. Вам может помочь следующее. Это пример кода , или вы можете просто перетащить в раздел дизайна файла xml.

...