2

I am trying to build a CardView based layout which contains both a MapFragment and a ConstraintLayout. The problem is that the cardview has rounded edges but this is not getting applied to the MapFragment and the ConstraintView inside the Card.

I have tried using Drawables with rounded corners as described here but it doesn't seem to work, and the Card's rounded corners either get drawn over by pointy edges or leave a border (depending on whether I use the drawable or leave it out).

What am I doing wrong, or missing?

CardView with corners not rounded

The Layout XML is as follows:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView 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="wrap_content"
    android:layout_margin="8dp"
    android:background="?android:attr/selectableItemBackground"
    android:clickable="true"
    android:focusable="true"
    app:cardCornerRadius="20dp">

    <android.support.constraint.ConstraintLayout
        android:id="@+id/view_card"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="5dp">

        <android.support.constraint.Guideline
            android:id="@+id/guideline"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintGuide_end="167dp"
            app:layout_constraintStart_toStartOf="parent" />

        <fragment
            android:id="@+id/map"
            android:name="com.google.android.gms.maps.MapFragment"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:cameraZoom="13"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@+id/guideline"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:liteMode="true"
            app:mapType="normal" />

        <android.support.constraint.ConstraintLayout
            android:id="@+id/linearLayout"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="@drawable/drawable_rounded_right"
            android:orientation="vertical"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/map"
            app:layout_constraintTop_toTopOf="parent">

            <android.support.constraint.ConstraintLayout
                android:id="@+id/view_foreground"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:background="@drawable/drawable_rounded_right_upper"
                android:visibility="visible"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                tools:layout_conversion_absoluteHeight="105dp"
                tools:layout_conversion_absoluteWidth="162dp"
                tools:layout_editor_absoluteY="5dp">

                <TextView
                    android:id="@+id/txtFname"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="8dp"
                    android:text="Name"
                    android:textAppearance="@style/TextAppearance.AppCompat.Large"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    tools:layout_conversion_absoluteHeight="30dp"
                    tools:layout_conversion_absoluteWidth="59dp" />

                <TextView
                    android:id="@+id/textView6"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Hours"
                    android:textAppearance="@style/TextAppearance.AppCompat.Small"
                    app:layout_constraintEnd_toEndOf="@+id/txtHours"
                    app:layout_constraintStart_toStartOf="@+id/txtHours"
                    app:layout_constraintTop_toBottomOf="@+id/txtHours"
                    tools:layout_conversion_absoluteHeight="19dp"
                    tools:layout_conversion_absoluteWidth="38dp"
                    tools:layout_editor_absoluteX="293dp"
                    tools:layout_editor_absoluteY="80dp" />

                <TextView
                    android:id="@+id/txtHours"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="8dp"
                    android:text="10"
                    android:textAppearance="@style/TextAppearance.AppCompat.Display1"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    tools:layout_conversion_absoluteHeight="46dp"
                    tools:layout_conversion_absoluteWidth="38dp" />

                <TextView
                    android:id="@+id/txtGender"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Male"
                    android:textAppearance="@style/TextAppearance.AppCompat.Body1"
                    app:layout_constraintStart_toStartOf="@+id/txtFname"
                    app:layout_constraintTop_toBottomOf="@+id/txtFname"
                    tools:layout_conversion_absoluteHeight="19dp"
                    tools:layout_conversion_absoluteWidth="31dp"
                    tools:layout_editor_absoluteX="185dp"
                    tools:layout_editor_absoluteY="64dp" />

                <TextView
                    android:id="@+id/textView24"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Age"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintStart_toStartOf="@+id/txtGender"
                    app:layout_constraintTop_toBottomOf="@+id/txtGender"
                    tools:layout_conversion_absoluteHeight="19dp"
                    tools:layout_conversion_absoluteWidth="24dp"
                    tools:layout_editor_absoluteX="185dp"
                    tools:layout_editor_absoluteY="83dp" />

                <TextView
                    android:id="@+id/txtAge"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="0"
                    app:layout_constraintBaseline_toBaselineOf="@+id/textView24"
                    app:layout_constraintStart_toEndOf="@+id/textView24"
                    tools:layout_conversion_absoluteHeight="19dp"
                    tools:layout_conversion_absoluteWidth="8dp"
                    tools:layout_editor_absoluteX="217dp"
                    tools:layout_editor_absoluteY="83dp" />


            </android.support.constraint.ConstraintLayout>

            <Button
                android:id="@+id/btnAction1"
                style="@style/Widget.AppCompat.Button.Borderless.Colored"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/drawable_rounded_right_lower"
                android:text="Action"
                android:textColor="@color/brightblue"
                android:textColorLink="@color/brightblue"
                android:textSize="12dp"
                android:textStyle="italic"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/view_foreground"
                tools:layout_conversion_absoluteHeight="30dp"
                tools:layout_conversion_absoluteWidth="88dp" />

        </android.support.constraint.ConstraintLayout>


    </android.support.constraint.ConstraintLayout>

</android.support.v7.widget.CardView>
kilokahn
  • 1,136
  • 2
  • 18
  • 38

1 Answers1

0

Enclosing the mapview in a cardview and changing the radius of the cardview can be a nice shot.

<android.support.v7.widget.CardView
    android:layout_width="300dp"
    android:layout_height="350dp"
    app:cardCornerRadius="12dp">
    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.MapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:cameraZoom="13"
        app:liteMode="true"
        app:mapType="normal" />
</android.support.v7.widget.CardView>

I really think your view hierarchy is quite nested and will amount to redundancy...(Good use of one Constraint layout can yield same interface, you have about 3). I guess you have to work on that.

Besides, you can add some margin to the map..., shift it from the edges. ( I hope that is what you want to achieve )

  • the redundancy is required as the cardView is a reusable component and the nested ConstraintLayout buttonLayout can be hidden, if the activity does not have any action to be taken on the card. I could try nesting it in the patientInfoLayout ConstraintLayout, though :) – kilokahn Jul 19 '18 at 07:18
  • Also the margin to the map would mean that the background color of the Card will show around the edges, which is not the effect I am going for - I wanted the map to aligned perfectly along the Card and have rounded edges as well. – kilokahn Jul 19 '18 at 07:20
  • Use a cardview to enclose the mapview fragment or use a nine-patch file that has 4 corners only to frame it as foreground – Barnabas Ukwuani Jul 19 '18 at 16:33
  • A CardView for the MapView? As in a nested CardView inside the main CardView? Also, the ConstraintView layout would still stick out. Any suggestions about that? – kilokahn Jul 19 '18 at 18:04
  • You can make the background transparent. – Barnabas Ukwuani Jul 20 '18 at 14:12
  • 1
    Yeah , a cardview for mapview – Barnabas Ukwuani Jul 20 '18 at 14:13
  • Could you please update your answer and perhaps add a code snippet to elaborate? I will then accept it. – kilokahn Jul 20 '18 at 18:14