【发布时间】:2020-07-16 03:12:04
【问题描述】:
如何在 android 中为布局制作圆角和阴影 任何帮助的例子? http://imgur.com/EecAwFX
【问题讨论】:
-
你有没有尝试写一些东西。你能具体说明你的问题吗?
标签: android layout rounded-corners
如何在 android 中为布局制作圆角和阴影 任何帮助的例子? http://imgur.com/EecAwFX
【问题讨论】:
标签: android layout rounded-corners
在您的 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 应用到您的布局中
【讨论】:
My reputation is less than 15 so I can't up vote your answer
尝试使用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>
这段代码产生了这种布局:
【讨论】: