Как я могу создать CardView и ImageView с закругленной границей? - PullRequest
0 голосов
/ 01 января 2019

Я хочу сделать следующий дизайн:

my design

Но я не знаю, как округлить ImageView и вертикальные линии.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical">


    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:layout_margin="10dp"
        app:cardCornerRadius="40dp">



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


</LinearLayout>

minSdkVersion 16
targetSdkVersion 28

РЕДАКТИРОВАНИЕ:

Согласно документу: CardView

Из-за дорогой природы отсечения закругленных углов на платформах до Lollipop CardView не обрезает дочерние элементы, которые пересекаются со скругленными углами.Вместо этого он добавляет отступы, чтобы избежать такого пересечения (см. SetPreventCornerOverlap (boolean), чтобы изменить это поведение).

Я написал этот код:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:background="#cccccc"
    android:orientation="vertical">


    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:layout_margin="10dp"
        android:clickable="true"
        android:focusable="true"
        android:foreground="?attr/selectableItemBackgroundBorderless"
        app:cardCornerRadius="40dp"
        app:cardElevation="0dp"
        app:cardPreventCornerOverlap="false">


        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">


            <com.makeramen.roundedimageview.RoundedImageView
                android:layout_width="170dp"
                android:layout_height="match_parent"
                android:scaleType="fitXY"
                android:src="@drawable/test_ex"
                app:riv_corner_radius_bottom_left="40dp"
                app:riv_corner_radius_top_left="40dp" />


            <View
                android:layout_width="4dp"
                android:layout_height="match_parent"
                android:layout_alignParentRight="true"
                android:layout_marginRight="10dp"
                android:background="@color/colorPrimaryDark" />


        </RelativeLayout>

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


</LinearLayout>

И результат в AndroidЭмулятор 4.3:

enter image description here

Как мне сделать отсечение?Какое лучшее решение?

Ответы [ 2 ]

0 голосов
/ 01 января 2019

Уже ответил charan

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:map="http://schemas.android.com/tools"
    android:id="@+id/cardview1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    card_view:cardCornerRadius="26dp"
    card_view:cardElevation="10dp"
    card_view:cardMaxElevation="2dp"
    card_view:contentPadding="0dp"
    android:layout_margin="@dimen/dp_8">

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="200dp"
        android:padding="5dp">
        <TextView
            android:id="@+id/name_tag"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="HELLO!"
            android:textSize="40sp"/>

       </RelativeLayout>

</androidx.cardview.widget.CardView>

Результат

0 голосов
/ 01 января 2019

Попробуйте следующий код:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical">


<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="150dp"
    android:layout_margin="10dp"
    app:cardCornerRadius="40dp"
    >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

    <ImageView
        android:layout_width="150dp"
        android:layout_height="match_parent"
        android:src="@drawable/ic_launcher_background"
        android:scaleType="centerCrop"
        android:id="@+id/image_"/>

    <View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#fff"
        android:rotation="15"
        android:layout_marginLeft="-30dp"
        android:layout_marginBottom="-40dp"
        android:layout_toRightOf="@id/image_">

    </View>


       <View
           android:layout_width="5dp"
           android:layout_height="match_parent"
           android:background="#be0202"
           android:layout_alignParentRight="true"
           android:layout_marginRight="20dp"/>

        <View
            android:layout_width="5dp"
            android:layout_height="match_parent"
            android:background="#be0202"
            android:layout_alignParentRight="true"
            android:layout_marginRight="30dp"/>

    </RelativeLayout>


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


</LinearLayout>

Результат:

Cardview with rounded corner ImageView

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...