【问题标题】:Android: show gradient like shadow using shape.xmlAndroid:使用 shape.xml 显示像阴影一样的渐变
【发布时间】:2016-09-20 06:46:49
【问题描述】:

您好,我正在尝试使用 shape.xml 仅在顶部获得类似渐变的阴影

从图像中我将按钮包裹在线性布局中,我想在布局顶部提供渐变。

如下所示,但没有成功

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
      <shape 
        android:shape="rectangle">
            <stroke android:width="1dp" android:color="#f0f0f0" />
            <solid android:color="#f0f0f0" />

        </shape>
   </item>

   <item android:top="1dp"> 
      <shape 
        android:shape="line">
       <gradient

        android:angle="90"
        android:type="linear"
        android:startColor="#FFFFFF"
        android:endColor="#000000" />
        </shape>
   </item>

</layer-list>

【问题讨论】:

    标签: android xml gradient android-drawable


    【解决方案1】:

    不需要使用Layer-list,你可以通过Gradient来实现。试试这个流动的代码 ->

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <gradient android:startColor="#b4909090" android:endColor="#b4fafafa" android:angle="90"/>
    </shape>
    

    根据需要更改startColorendColor。结果是 ->

    【讨论】:

    • 该代码正在为整个线性布局提供渐变..只想在布局中添加一条线
    • 您没有指定如何使用它。如果您在视图上方有一个ImageView 并将其设置为ImageView 的背景,则这是有效的。当您将此作为背景应用到LinearLayout 时,整个视图将具有渐变背景。他希望他的背景是白色的,顶部有渐变边框。
    【解决方案2】:

    简单使用:

    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
    <gradient 
      android:type="linear"
      android:centerX="78%" 
      android:startColor="#FFf7f7f7" 
      android:centerColor="#FFC0C0C0" 
      android:endColor="#FFbebebe" 
      android:angle="90"/>
    </shape>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-25
      • 2017-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-21
      相关资源
      最近更新 更多