如何在android中为布局制作圆角和阴影 任何帮助的例子? http://imgur.com/EecAwFX
答案 0 :(得分:0)
在rounde_corner.xml
文件夹中创建drawable
,然后将以下内容粘贴到
<?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
应用于您的布局
答案 1 :(得分:0)
尝试使用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>
此代码产生这种布局: