0

У меня проблема, не могу разместить ImageView(синенький логотип) на передний план, а linearLayout(в которому находится ImageView) на задний план. Как это можно сделать?

Вот так приложение выглядит на данный момент

Вот так приложение выглядит на данный момент

А вот так должно выглядеть

А вот так должно выглядеть

код xml прикрепляю ниже:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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:background="@drawable/background"
android:fillViewport="true"
tools:context=".MainActivity">

<LinearLayout
    android:id="@+id/linear_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:id="@+id/inchat"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:fontFamily="@font/cookie_regular"
        android:textSize="40dp"
        android:textColor="@color/main_color"
        android:text="Hello world" />


    <!-- content goes here -->

    <!-- stretching frame layout, using layout_weight -->
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

    </FrameLayout>

    <LinearLayout
        android:id="@+id/linear_bottom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/background_white"
        android:layout_gravity="center_horizontal"
        android:orientation="vertical">
        <!-- your bottom content -->

        <RelativeLayout
            android:layout_width="match_parent"
            android:gravity="center"
            android:layout_height="wrap_content">
            <ImageView
                android:id="@+id/imageView"
                android:layout_width="72dp"
                android:layout_height="72dp"
                android:layout_marginTop="-40dp"
                app:srcCompat="@drawable/splash_icon" />
        </RelativeLayout>

        <Button
            android:id="@+id/button2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Button" />

        <Button
            android:id="@+id/button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Button" />
    </LinearLayout>
</LinearLayout></ScrollView>
7
  • Из описания не очень ясно что вам нужно. Попробуйте нарисовать что хотите получить и приложите разметку экрана текстом.
    – ЮрийСПб
    19 мая 2021 в 17:48
  • @ЮрийСПб Извините, уже исправил 19 мая 2021 в 17:54
  • 1
    Правильным тут будет использование ConstraintLayout - сможете картинку расположить над контейнером с кнопками. RelativeLayout вообще в настоящее время никто не использует.
    – ЮрийСПб
    19 мая 2021 в 18:26
  • @ЮрийСПб К сожалению замена на ConstraintLayout не помогла. Мне не нужно размещать картинку над контейнером с кнопками, мне нужно лишь чтобы картинка на 50% выходила из контейнера с кнопками(50% картинки в контейнере, 50% за контейнером) 19 мая 2021 в 18:45
  • Надо не заменять, а полностью переписать всю разметку внутри ScrollView, заменив главный LinearLayout на ConstraintLayout. Картинку убрать из внутреннего LinearLayout и поместить специальным образом над верхом внуреннего LinearLayout через constraintTopToTopOf="ТУТ ID внутреннего линеара" и constraintBottomToBottomOf="ТУТ ID внутреннего линеара"
    – ЮрийСПб
    19 мая 2021 в 18:49

1 ответ 1

0

Попробуйте вот эту разметку

<?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"
    android:background="#ECECEC"
    android:padding="8dp">

    <TextView
        android:id="@+id/helloWorld"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="75dp"
        android:text="Hello world"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <FrameLayout
        android:id="@+id/dialog_content"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="125dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@id/helloWorld">

        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="40dp"
            app:cardCornerRadius="8dp">

            <androidx.constraintlayout.widget.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="40dp"
                android:paddingBottom="75dp">

                <Button
                    android:id="@+id/button1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="16dp"
                    android:text="Button1"
                    app:layout_constraintTop_toTopOf="parent" />

                <Button
                    android:id="@+id/button2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="16dp"
                    android:text="Button1"
                    app:layout_constraintTop_toBottomOf="@id/button1" />

            </androidx.constraintlayout.widget.ConstraintLayout>
        </androidx.cardview.widget.CardView>
    </FrameLayout>

    <ImageView
        android:layout_width="80dp"
        android:layout_height="80dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@id/dialog_content"
        tools:src="@tools:sample/avatars" />

</androidx.constraintlayout.widget.ConstraintLayout>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.