渐变背景,这并不规模 [英] Gradient Background that doesn't scale

查看:101
本文介绍了渐变背景,这并不规模的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个梯度是230dp高(即,不是整个屏幕),同屏纯色的其余部分。我无法弄清楚如何做到这一点 - 一切我尝试用渐变扩展到充满整个屏幕的结束。我现在的XML看起来像这样:

 <?XML版本=1.0编码=UTF-8&GT?;
<层列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>    <项目的android:顶部=230dp>
        <形状机器人:形状=矩形>
            <彩色机器人:颜色=#333333/>
        < /形状>
    < /项目>
    <项目>
        <形状机器人:形状=矩形>
            <梯度
                机器人:角=270
                机器人:ENDCOLOR =#333333
                机器人:startColor =##000000
                机器人:类型=线性/>            <大小机器人:身高=230dp/>
        < /形状>
    < /项目>< /层列表>

我然后应用绘制为背景,以我的LinearLayout在XML:

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:背景=#333333>
    <的LinearLayout
        机器人:ID =@ + ID /容器
        机器人:方向=垂直
        机器人:layout_height =FILL_PARENT
        机器人:layout_width =FILL_PARENT
        机器人:背景=@绘制/ grey_gradient_bg>        <! - 一堆内容,按钮等 - >    < / LinearLayout中>
< / LinearLayout中>

但梯度扩展以填充整个屏幕。

我一直在使用的背景PNG试过,但我得到的the这里描述带的问题,该修复程序并没有帮助我呢。


解决方案

  1. 使用一个RelativeLayout的,而不是一个的LinearLayout

  2. 而不是使用您的梯度布局的主要容器的背景,添加子视图,设置高度明确你想要(230dp)的大小,并设置以渐变的背景。

I need to create a gradient that is 230dp high (i.e., not the whole screen), with the rest of the screen a solid color. I can't figure out how to do this -- everything I try ends up with the gradient expanding to fill the whole screen. My current XML looks like this:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:top="230dp">
        <shape android:shape="rectangle" >
            <color android:color="#333333" />
        </shape>
    </item>
    <item>
        <shape android:shape="rectangle" >
            <gradient
                android:angle="270"
                android:endColor="#333333"
                android:startColor="#D9D9D9"
                android:type="linear" />

            <size android:height="230dp" />
        </shape>
    </item>

</layer-list>

I then apply that drawable as the background to my LinearLayout in XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#333333" >
    <LinearLayout
        android:id="@+id/container"
        android:orientation="vertical"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:background="@drawable/grey_gradient_bg" >

        <!-- a bunch of content, buttons, etc. -->

    </LinearLayout>
</LinearLayout>

But the gradient expands to fill the whole screen.

I have tried using a PNG for the background, but I get the banding problems described here, and the fixes haven't helped me yet.

解决方案

  1. Use a RelativeLayout instead of a LinearLayout
  2. Instead of using your gradient as a background of the main container of the layout, add a child View, set the height explicitly to the size you want (230dp), and set the background of that view to your gradient.

这篇关于渐变背景,这并不规模的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆