How to make layout with rounded corners..?

后端 未结 18 2894
独厮守ぢ
独厮守ぢ 2020-11-22 09:37

How can I make a layout with rounded corners? I want to apply rounded corners to my LinearLayout.

相关标签:
18条回答
  • 2020-11-22 10:23

    If you would like to make your layout rounded, it is best to use the CardView, it provided many features to make the design beautiful.

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        card_view:cardCornerRadius="5dp">
          <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
    
                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight=".3"
                    android:text="@string/quote_code"
                    android:textColor="@color/white"
                    android:textSize="@dimen/text_head_size" />
          </LinearLayout>
    </android.support.v7.widget.CardView>
    

    With this card_view:cardCornerRadius="5dp", you can change the radius.

    0 讨论(0)
  • 2020-11-22 10:23

    Create your xml in drawable, layout_background.xml

     <?xml version="1.0" encoding="utf-8"?>
        <shape xmlns:android="http://schemas.android.com/apk/res/android" >
          <solid android:color="@color/your_colour" />
          <stroke
                android:width="2dp"
                android:color="@color/your_colour" />
          <corners android:radius="10dp" />      
        </shape>
     <--width, color, radius should be as per your requirement-->
    

    and then, add this in your layout.xml

     android:background="@drawable/layout_background"
    
    0 讨论(0)
  • 2020-11-22 10:24

    Try this...

    1.create drawable xml(custom_layout.xml):

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" >
    
    <solid android:color="#FFFFFF" />
    
    <stroke
        android:width="2dp"
        android:color="#FF785C" />
    
    <corners android:radius="10dp" />
    
    </shape>
    

    2.add your view background

    android:background="@drawable/custom_layout"
    
    0 讨论(0)
  • 2020-11-22 10:24

    I've taken @gauravsapiens answer with my comments inside to give you a reasonable apprehension of what the parameters will effect.

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
    
        <!-- Background color -->
        <solid android:color="@color/white" />
    
        <!-- Stroke around the background, width and color -->
        <stroke android:width="4dp" android:color="@color/drop_shadow"/>
    
        <!-- The corners of the shape -->
        <corners android:radius="4dp"/>
    
        <!-- Padding for the background, e.g the Text inside a TextView will be 
        located differently -->
        <padding android:left="10dp" android:right="10dp" 
                 android:bottom="10dp" android:top="10dp" />
    
    </shape>
    

    If you're just looking to create a shape that rounds the corners, removing the padding and the stroke will do. If you remove the solid as well you will, in effect, have created rounded corners on a transparent background.

    For the sake of being lazy I have created a shape underneath, which is just a solid white background with rounded corners - enjoy! :)

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
    
        <!-- Background color -->
        <solid android:color="@color/white" />
    
        <!-- The corners of the shape -->
        <corners android:radius="4dp"/>
    
    </shape>
    
    0 讨论(0)
  • 2020-11-22 10:24

    Step 1: Define bg_layout.xml in drawables folder.

    Step 2: Add bg_layout.xml as background to your layout.

        <?xml version="1.0" encoding="UTF-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <solid
            android:color="#EEEEEE"/> <!--your desired colour for solid-->
    
        <stroke
            android:width="3dp"
            android:color="#EEEEEE" /> <!--your desired colour for border-->
    
        <corners
            android:radius="50dp"/> <!--shape rounded value-->
    
    </shape>
    
    0 讨论(0)
  • 2020-11-22 10:25
     <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:padding="@dimen/_10sdp"
    android:shape="rectangle">
    
    <solid android:color="@color/header" />
    
    <corners
        android:bottomLeftRadius="@dimen/_5sdp"
        android:bottomRightRadius="@dimen/_5sdp"
        android:topLeftRadius="@dimen/_5sdp"
        android:topRightRadius="@dimen/_5sdp" />
    

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