Dzh*_*eyt 8 android android-xml android-background
基本上,我试图创建以下背景:

我用于背景的drawable中使用的传统渐变仅支持开始颜色,中间颜色和结束颜色.
但是,正如您从模型中看到的那样,我试图在形状的顶部和底部仅创建一个轻微的叠加/阴影,#50000000颜色(黑色,不透明度为50%).
Joe*_*des 10
如果您在布局视图中使用它,那么您只需创建View一个渐变背景并将其放置在布局的开头和结尾.
例如:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/parent">
<View
android:layout_width="fill_parent"
android:layout_height="5dp"
android:background="@drawable/gradient" />
<!-- Your other child views -->
<View
android:layout_width="fill_parent"
android:layout_height="5dp"
android:background="@drawable/gradient" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
你的gradient.xml文件将有这个:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:startColor="#FFFFFF" android:endColor="#000000" android:angle="90"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
您可以为父布局指定蓝色背景颜色.
你基本上会得到这样的东西:

[编辑]
您可以创建两个drawable - gradient_top.xml并gradient_bottom.xml获得正确的角度
我更喜欢这样做而不是乱七八糟.虽然,尽管如此,我希望谷歌继续提供内置的投影支持,因为它们非常普遍.
只是以更完整的例子为基础构建JoelFernandez解决方案:
容器:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="[your_container_height]"
android:background="@drawable/container_bg_color">
<View
android:layout_width="match_parent"
android:layout_height="12dp"
android:layout_alignParentTop="true"
android:background="@drawable/container_gradient_top"/>
<View
android:layout_width="match_parent"
android:layout_height="12dp"
android:layout_alignParentBottom="true"
android:background="@drawable/container_gradient_bottom" />
<!-- Insert your content here -->
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
背景颜色(container_bg_color.xml):
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:thickness="0dp"
android:shape="rectangle">
<gradient android:startColor="#4a6fb4"
android:endColor="@color/deepBlue"
android:angle="135"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
Top Gradient(container_gradient_top.xml):
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:thickness="0dp"
android:shape="rectangle">
<gradient
android:startColor="#00222222"
android:centerColor="#11111111"
android:endColor="#44000000"
android:angle="90"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
底部渐变(container_gradient_bottom.xml):
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:thickness="0dp"
android:shape="rectangle">
<gradient
android:startColor="#44000000"
android:centerColor="#11111111"
android:endColor="#00222222"
android:angle="90"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
结果:
| 归档时间: |
|
| 查看次数: |
15553 次 |
| 最近记录: |