【问题标题】:Android rectangle background gradientAndroid矩形背景渐变
【发布时间】:2017-05-04 06:48:25
【问题描述】:

我想创建一个从内到外的背景渐变。在外面它应该变得更暗。这是一张图片:

谁能给我一些建议,我可以如何创建这样的东西? 或者我应该为此拍照吗?如果是,那么不同的屏幕分辨率是怎么回事?或者关于风景/肖像模式?

【问题讨论】:

  • 如果您使用九个补丁图像,那么当您一次旋转屏幕时可能会出现问题,但如果您使用的是 xml 文件,则永远不会产生问题。所以根据我的观点,您有使用渐变 (.xml) 文件实现此功能。 @MyNewName

标签: android background gradient


【解决方案1】:

根据需要使用此更改颜色

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
    <gradient
        android:type="radial"
        android:startColor="#f15330"
        android:endColor="#da0000"
        android:gradientRadius="150dp"
        />
   <size android:height="400dp"
       android:width="250dp"/>
</shape>

【讨论】:

    【解决方案2】:

    是的,你可以使用nine patch image来实现这个类型的gredient

    但是如果你想使用 gredient 那么我认为这会对你有所帮助..

     <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
        <gradient 
        android:type="radial"
        android:centerX="50%" 
        android:centerY="50%" 
        android:startColor="#FFff0000" 
        android:endColor="#FF000000" 
        android:gradientRadius="100"/>
    </shape>
    

    this 是 olnline 工具,您可以在其中创建 gredient,您可以使用 android tab 抓取代码..

    【讨论】:

    • 如果您使用九个补丁图像,那么当您一次旋转屏幕时可能会出现问题,但如果您使用的是 xml 文件,则永远不会产生问题。所以根据我的观点,您有使用渐变 (.xml) 文件实现此功能。 @MyNewName
    【解决方案3】:

    你想要它像cardview一样吗?或者你也可以试试这个,

        <?xml version="1.0" encoding="UTF-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    
        <item>
            <shape android:shape="rectangle" >
                <gradient
                    android:angle="360"
                    android:centerColor="#e95a22"
                    android:endColor="#ff00b5"
                    android:gradientRadius="360"
                    android:startColor="#006386"
                    android:type="sweep" />
    
                <stroke
                    android:width="2dp"
                    android:color="#ff207d94" />
            </shape>
        </item>
        <item
            android:bottom="2dp"
            android:left="2dp"
            android:right="2dp"
            android:top="2dp">
            <shape android:shape="rectangle" >
                <solid android:color="#fff" />
            </shape>
        </item>
    
    </layer-list>
    

    【讨论】:

      猜你喜欢
      • 2020-03-10
      • 2011-08-24
      • 2020-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多