按钮未移至CardView上方

时间:2018-10-15 05:05:37

标签: android android-button android-cardview

这是我在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 :(得分:0)

以此更改您的card_edge.xml

Public Sub Document_AcceptAll()

'Public Declarations
    Dim Sctn As Section
    Dim NewRevision As Revision
    Dim StorySect As Word.Range
    Dim HdFt As HeaderFooter

    On Error GoTo RevErr

    For Each StorySect In ActiveDocument.StoryRanges
        'Debug.Print StorySect.StoryType
        For Each NewRevision In StorySect.Revisions
            Select Case NewRevision.Type
                Case Is <> 1, 2 Or 9    '1: wdRevisionInsert  2: wdRevisionDelete  9: wdRevisionReplace
                    NewRevision.Accept

                Case Else

            End Select

        Next NewRevision
        Do While Not (StorySect.NextStoryRange Is Nothing)
            Set StorySect = StorySect.NextStoryRange

            For Each NewRevision In StorySect.Revisions
                Select Case NewRevision.Type
                    Case Is <> 1, 2 Or 9    '1: wdRevisionInsert  2: wdRevisionDelete  9: wdRevisionReplace
                        NewRevision.Accept

                    Case Else

                End Select

            Next NewRevision
        Loop
        Next StorySect '<<

lbl_Exit:
        Exit Sub
RevErr:
        If Err.Number <> 5852 Then
            Err.Clear
            GoTo lbl_Exit
        Else
            Err.Clear
            Resume
        End If
End Sub

activity.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>

答案 1 :(得分:0)

尝试

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