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

Я хочу создать следующий экран, который содержит логотип приложения, изображение значка успеха / неудачи, информационное сообщение и кнопку ОК.

enter image description here

Вот этокод.Для этого я использую линейный макет.

<LinearLayout
android:id="@+id/statusLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="@android:color/white"
android:weightSum="2"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
    android:id="@+id/statusTopRelativeLayout"
    android:background="@android:color/holo_blue_bright"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:orientation="vertical"
    android:layout_weight="1">
    <ImageView
        android:id="@+id/client_logo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/no_image_description"
        android:src="@drawable/client_logo"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"/>
</RelativeLayout>
<RelativeLayout
    android:id="@+id/statusBottomRelativeLayout"
    android:background="@android:color/holo_blue_light"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1">
    <TextView
        android:id="@+id/statusText"           
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="50dp"
        android:text="@string/statusText"
        android:textSize="50sp"/>
    <Button
        android:id="@+id/btnOk"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/statusText"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="50dp"            
        android:clickable="true"
        android:focusable="true"
        android:onClick="goToHomeScreen"
        android:paddingBottom="15dp"
        android:paddingTop="15dp"
        android:text="@string/ok"
        android:textColor="#ffffff"
        android:textSize="40sp"/>
</RelativeLayout>

Как разместить изображение значка успеха / неудачи поверх двух макетов?

Ответы [ 3 ]

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

Попробуйте это

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    android:orientation="vertical">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/nilu"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@color/colorPrimary"
            android:orientation="vertical"
            android:paddingBottom="30dp">


            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="NILU" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="NILU" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="NILU" />


        </LinearLayout>

        <LinearLayout
            android:id="@+id/nilu2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/nilu"
            android:layout_weight="1"
            android:background="@color/colorAccent"
            android:orientation="vertical">


            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="NILU" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="NILU" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="NILU" />

        </LinearLayout>
    </LinearLayout>


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        android:orientation="horizontal">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:src="@mipmap/ic_launcher_round" />


    </RelativeLayout>


</RelativeLayout>

OUTPUT

enter image description here

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

Вы можете использовать ограничение, чтобы упростить

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <android.support.constraint.Guideline
        android:id="@+id/center"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.5"/>

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toTopOf="@id/center"
        android:background="#ffffff"/>

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintTop_toTopOf="@id/center"
        app:layout_constraintBottom_toBottomOf="parent"
        android:background="#00ffff"/>

    <ImageView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="#ff8801"
        app:layout_constraintTop_toTopOf="@id/center"
        app:layout_constraintBottom_toBottomOf="@id/center"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />

</android.support.constraint.ConstraintLayout>

Выход:

enter image description here

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

Parent RelativeLayout

  • добавить дочерний LinearLayout в качестве fillParent и назначить весовую сумму 2. добавить два макеты с 1 весом каждый. (добавить индивидуальную реализацию для каждого макет в соответствии с вашими требованиями.)
  • добавить второго ребенка в относительном макет как изображение / кнопка для этого хорошего знака и установить его в центре Родитель.

Это решит вашу проблему

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...