Кнопка не перемещается выше CardView - PullRequest
0 голосов
/ 15 октября 2018

Это то, что я разработал в Android Studio

Expected Image

Это то, что я получаю на свой мобильныйустройство:

Actual Image

Проблема в том, что я добавил перевод z и высоту для моей кнопки и изображения в макете ограничения.Но перевод z работает в случае просмотра изображения, но не для кнопки.

Это Activity.xml:

<?xml version="1.0" encoding="utf-8"?>

<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"
xmlns:card_view="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">


<android.support.v7.widget.CardView
    android:id="@+id/cardView2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:elevation="@dimen/cardview_default_elevation"
    android:background="@android:drawable/dialog_holo_light_frame"
    app:cardCornerRadius="18dp"
    android:layout_marginBottom="2dp"
    android:layout_marginTop="2dp"
    android:layout_marginRight="30dp"
    android:layout_marginLeft="30dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="1.0">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/textView2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="56dp"
            android:layout_marginLeft="56dp"
            android:layout_marginTop="18dp"
            android:fontFamily="serif"
            android:text="Popcorns"
            android:textColor="@android:color/black"
            android:textSize="26sp"
            android:textStyle="bold"
            android:translationZ="2dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:layout_marginBottom="16dp"
            android:text="28 items"
            android:textSize="13sp"
            android:translationZ="2dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="@+id/textView2"
            app:layout_constraintTop_toBottomOf="@+id/textView2"
            app:layout_constraintVertical_bias="0.0" />

    </android.support.constraint.ConstraintLayout>


</android.support.v7.widget.CardView>


<ImageView
    android:id="@+id/imageView"
    android:layout_width="65dp"
    android:layout_height="65dp"
    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:adjustViewBounds="false"
    android:src="@drawable/popcorn1"
    android:translationZ="5dp"
    android:elevation="5dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toStartOf="@+id/cardView2"
    app:layout_constraintHorizontal_bias="0.098"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<Button
    android:id="@+id/button"
    android:layout_width="32.5dp"
    android:layout_height="32.5dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="16dp"
    android:layout_marginRight="16dp"
    android:layout_marginBottom="8dp"
    android:background="@drawable/card_edge"
    android:drawableTop="@drawable/baseline_chevron_right_24"
    android:translationZ="5dp"
    android:elevation="5dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent"

    />

Это card_edge.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle" >
    <corners
        android:radius="50dp"/>

    <solid android:color="@color/cardview_light_background"/>
</shape>

Ответы [ 2 ]

0 голосов
/ 15 октября 2018

попробуйте

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


    <RelativeLayout
        android:id="@+id/relative"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.CardView
            android:id="@+id/cardView2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:layout_marginTop="2dp"
            android:layout_marginRight="30dp"
            android:layout_marginBottom="2dp"
            android:background="@android:drawable/dialog_holo_light_frame"
            android:elevation="@dimen/cardview_default_elevation"
            app:cardCornerRadius="18dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="1.0">

            <android.support.constraint.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <TextView
                    android:id="@+id/textView2"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="56dp"
                    android:layout_marginLeft="56dp"
                    android:layout_marginTop="18dp"
                    android:fontFamily="serif"
                    android:text="Popcorns"
                    android:textColor="@android:color/black"
                    android:textSize="26sp"
                    android:textStyle="bold"
                    android:translationZ="2dp"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="4dp"
                    android:layout_marginBottom="16dp"
                    android:text="28 items"
                    android:textSize="13sp"
                    android:translationZ="2dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintStart_toStartOf="@+id/textView2"
                    app:layout_constraintTop_toBottomOf="@+id/textView2"
                    app:layout_constraintVertical_bias="0.0" />

            </android.support.constraint.ConstraintLayout>


        </android.support.v7.widget.CardView>

    </RelativeLayout>

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="65dp"
        android:layout_height="65dp"
        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:adjustViewBounds="false"
        android:elevation="5dp"
        android:src="@drawable/popcorn1"
        android:translationZ="5dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/relative"
        app:layout_constraintHorizontal_bias="0.098"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button"
        android:layout_width="32.5dp"
        android:layout_height="32.5dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginBottom="8dp"
        android:background="@drawable/card_edge"
        android:drawableTop="@drawable/baseline_chevron_right_24"
        android:elevation="5dp"
        android:translationZ="5dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"

        />

</android.support.constraint.ConstraintLayout>
0 голосов
/ 15 октября 2018

измените свой card_edge.xml с этим

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item>
        <shape android:shape="oval">
            <solid android:color="@color/gray"/>
            <!--shadow Color-->
        </shape>
    </item>

    <item
        android:left="1dp"
        android:right="1dp"
        android:top="0dp"
        android:bottom="2dp">
        <shape android:shape="oval">
            <solid android:color="@color/white"/>//Background Color
        </shape>
    </item>
</layer-list>

activity.xml как

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


<android.support.v7.widget.CardView
    android:id="@+id/cardView2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:elevation="@dimen/cardview_default_elevation"
    android:background="@android:drawable/dialog_holo_light_frame"
    app:cardCornerRadius="18dp"
    android:layout_marginBottom="2dp"
    android:layout_marginTop="2dp"
    android:layout_marginRight="30dp"
    android:layout_marginLeft="30dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="1.0">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/textView2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="56dp"
            android:layout_marginLeft="56dp"
            android:layout_marginTop="18dp"
            android:fontFamily="serif"
            android:text="Popcorns"
            android:textColor="@android:color/black"
            android:textSize="26sp"
            android:textStyle="bold"
            android:translationZ="2dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:layout_marginBottom="16dp"
            android:text="28 items"
            android:textSize="13sp"
            android:translationZ="2dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="@+id/textView2"
            app:layout_constraintTop_toBottomOf="@+id/textView2"
            app:layout_constraintVertical_bias="0.0" />

    </android.support.constraint.ConstraintLayout>


</android.support.v7.widget.CardView>


<ImageView
    android:id="@+id/imageView"
    android:layout_width="65dp"
    android:layout_height="65dp"
    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:adjustViewBounds="false"
    android:translationZ="5dp"
    android:src="@drawable/popcorn1"
    android:elevation="5dp"
    android:layout_centerVertical="true" />
<Button
    android:id="@+id/button"
    android:layout_width="32.5dp"
    android:layout_height="32.5dp"
    android:padding="4dp"
    android:background="@drawable/card_edge"
    android:drawableTop="@drawable/baseline_chevron_right_24"
    android:layout_centerVertical="true"
    app:elevation="5dp"
    android:layout_alignParentRight="true"
    android:layout_marginRight="15dp"
    android:layout_alignParentEnd="true"
    android:layout_marginEnd="15dp" />

...