Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

Manter radius no cardview usando constraintLayout

Olá

Estou utilizando ConstraintLayout e não estou conseguindo manter o efeito do radius do cardview porque o ConstraintLayout da header fica encima. Segue código da activity:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:cardElevation="10dp"
    app:cardUseCompatPadding="true"
    app:cardCornerRadius="8dp">

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

        <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/detalhes_prova_header"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#00A8EC"
            android:padding="10dp">

            <TextView
                android:id="@+id/detalhes_prova_materia"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:text="Matéria"
                android:textColor="#fff"
                android:textSize="20sp"
                android:textStyle="bold"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:id="@+id/detalhes_prova_data"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:text="10/10/2017"
                android:textColor="#fff"
                android:textSize="20sp"
                android:textStyle="bold"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

        </android.support.constraint.ConstraintLayout>

        <ListView
            android:id="@+id/detalhes_prova_topicos"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/detalhes_prova_header"></ListView>

    </android.support.constraint.ConstraintLayout>

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

2 respostas
solução!

Não sei se essa solução seria mais adequada, mas deu certo, segue uma solução:

Layout do card:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    app:cardElevation="10dp"
    app:cardUseCompatPadding="true"
    app:cardCornerRadius="@dimen/corner_cardx">

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

        <android.support.constraint.ConstraintLayout
            android:id="@+id/detalhes_prova_header"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/background_color_with_radius"
            android:padding="10dp">

            <TextView
                android:id="@+id/detalhes_prova_materia"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                tools:text="Matéria"
                android:textColor="#fff"
                android:textSize="20sp"
                android:textStyle="bold"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:id="@+id/detalhes_prova_data"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                tools:text="10/10/2017"
                android:textColor="#fff"
                android:textSize="20sp"
                android:textStyle="bold"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

        </android.support.constraint.ConstraintLayout>

        <ListView
            android:id="@+id/detalhes_prova_topicos"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/detalhes_prova_header"/>

    </android.support.constraint.ConstraintLayout>

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

Drawable para borda do constrant do seu header ( /drawable/background_color_with_radius.xml ):

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:topLeftRadius="@dimen/corner_cardx" android:topRightRadius="@dimen/corner_cardx"/>
    <solid android:color="@color/header_cardx"/>
</shape>

Obs: extrai o valor do radius do seu card para o xml de dimensoes assim os dois lugares vão garantir o mesmo valor; Também fiz a extração da cor para o xml de cores e utilizei o tools para definir o texto, assim garante que seja somente para exibiçao.

Veja como ficou

Olá Guilherme

Funcionou perfeitamente.

Obrigado.