Unable to get exact circle shape when using card view

前端 未结 11 1867
旧时难觅i
旧时难觅i 2020-12-25 10:12

I\'m using card view for floating action button in android material design. I\'m using following code for get the circle



        
相关标签:
11条回答
  • 2020-12-25 10:51
    <androidx.cardview.widget.CardView
            android:layout_width="60dp"
            android:layout_marginStart="150dp"
            app:cardCornerRadius="360dp"
            android:layout_height="60dp">
    
    0 讨论(0)
  • 2020-12-25 10:51

    Yes, I have achieved it by reducing half of the CardCornerRadius to its View's Height.

    0 讨论(0)
  • 2020-12-25 10:56

    I tried your code and found out that the Cards were less round with respect to the increase in the card elevation value.Try setting it to zero and this at least makes it look better.

    card_view:cardElevation="0dp";
    

    But a probably better option would be to use the FloatingActionButton for the round button

    <android.support.design.widget.FloatingActionButton
        android:src="@drawable/your_drawble_name"
        app:fabSize="normal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    
    0 讨论(0)
  • 2020-12-25 10:59

    Using CardView to obtain circular background with shadow can be quiet troublesome intead use layer-list in drawable to get the desired output.

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item>
            <shape android:shape="oval">
                <!--shadow color you want-->
                <solid android:color="#C3C1C1"/>
            </shape>
        </item>
    
        <item
            android:left="0dp"
            android:right="0dp"
            android:top="0dp"
            android:bottom="2dp">
            <shape android:shape="oval">
                <solid android:color="@color/white"/>
            </shape>
        </item>
    </layer-list>
    
    0 讨论(0)
  • 2020-12-25 11:05

    I came up with simple Solution of Using a Drawable and it looks amazing!

    Get Drawable here https://drive.google.com/open?id=0B4Vo_ku-aIKzUFFnUjYxYVRLaGc

    0 讨论(0)
  • 2020-12-25 11:07

    To get a perfect circle shape using a card view, corner radius should be 1/2 of width or height (taking into consideration that it is a square). also, I have noticed that you are using card_view params, don't.

    <android.support.v7.widget.CardView
    android:layout_width="38dp"
    android:layout_height="38dp"
    app:cardCornerRadius="19dp"
    app:cardElevation="6dp"
    android:layout_marginBottom="10dp"
    android:layout_marginRight="10dp"
    android:id="@+id/fab"
    android:background="@color/blue"
    >
    

    0 讨论(0)
提交回复
热议问题