圆角 android

Rounded Corners android

如何为 android 中的布局制作圆角和阴影 有什么帮助的例子吗? http://imgur.com/EecAwFX

在您的 drawable 文件夹中创建 rounde_corner.xml 并将以下内容粘贴到其中

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/white"/>
    <corners android:radius="4dp"/>
</shape>

并将其作为 background 应用于您的布局

尝试使用cardview。然后为圆角设置cardCornerRadius,为阴影设置cardElevation

Check out this link for further documentation.

例如:

 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/material_blue_500"
        android:paddingBottom="1dp">

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/stock_detail_margin"
            android:layout_marginEnd="@dimen/heading_item_extra_padding"
            android:layout_marginLeft="@dimen/heading_item_extra_padding"
            android:layout_marginRight="@dimen/heading_item_extra_padding"
            android:layout_marginStart="@dimen/heading_item_extra_padding"
            android:layout_marginTop="@dimen/stock_detail_margin"
            app:cardCornerRadius="5dp"
            app:cardElevation="15dp">


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="3"
                    android:gravity="center"
                    android:orientation="vertical">


                    <TextView
                        android:id="@+id/txt_symbol"
                        style="@style/StockSymbolTextStyle"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="5dp"
                        android:gravity="center"
                        android:hint="YHOO" />


                    <TextView
                        android:id="@+id/txt_company"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="5dp"
                        android:gravity="center"
                        android:hint="Yahoo Incorporated Inc."
                        android:textAppearance="?android:attr/textAppearanceSmall" />

                </LinearLayout>

                <android.support.v7.widget.CardView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_margin="5dp"
                    android:layout_weight="1"
                    app:cardBackgroundColor="@android:color/holo_orange_dark"
                    app:cardCornerRadius="5dp">

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:gravity="center"
                        android:orientation="vertical">


                        <TextView
                            android:id="@+id/txt_price"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="5dp"
                            android:gravity="center"
                            android:text="57.90"
                            android:textAppearance="?android:attr/textAppearanceLarge"
                            android:textColor="@android:color/white" />

                        <TextView
                            android:id="@+id/txt_percent"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="5dp"
                            android:gravity="center"
                            android:text="-98.2%"
                            android:textAppearance="?android:attr/textAppearanceSmall"
                            android:textColor="@android:color/white" />

                        <TextView
                            android:id="@+id/txt_change_amt"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="5dp"
                            android:gravity="center"
                            android:text="-2.44"
                            android:textAppearance="?android:attr/textAppearanceSmall"
                            android:textColor="@android:color/white" />
                    </LinearLayout>
                </android.support.v7.widget.CardView>


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

    </LinearLayout>

这段代码产生这种布局: