是否可以在不使用图像的情况下在背景中绘制渐变效果?

时间:2015-11-05 13:09:37

标签: android

  

我可以在不使用仅使用颜色的图像的情况下设置背景渐变。

     请告诉我。感谢

4 个答案:

答案 0 :(得分:1)

您可以使用以下方式创建在线渐变: -

http://angrytools.com/gradient/

并将其作为xml文件放入drawable文件夹

将背景设为图像

答案 1 :(得分:0)

是的,你只需添加颜色即可。

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
    android:startColor="#83a4d4"
    android:endColor="#b6fbff"
    android:angle="45"/> 
    <corners 
     android:bottomRightRadius="10dp" 
     android:bottomLeftRadius="10dp" 
     android:topLeftRadius="10dp" 
     android:topRightRadius="10dp"/>    
</shape>

答案 2 :(得分:0)

是的,你可以做到! 您可以使用Shape Drawable来实现渐变效果。 可以在此处找到Shape Drawable XML文件的语法: http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape

假设您使用以下内容制作了grad_bg.xml:

NSMutableArray

在应用程序的res / drawables /文件夹中准备好XML后,可以使用视图标记中的以下属性将其设置为背景,并将布局中的元素(如LinearLayout)设置为按钮和TextView等窗口小部件:

(
   {
    Realimg = "<UIImage: 0x13951b130>, {800, 600}";
    "bid_accepted" = 1;
    "bid_amount" = 100;
    "bid_amount_num" = 100;
    "bid_cur_name" = USD;
    "bid_cur_symb" = $;
    "bid_currencycode" = 4;
    "bid_date" = "05 Nov 2015";
    "bid_msg" = testing;
    "bid_user_id" = 2;
    "nego_id" = 612;
    "pas_count" = 5;
    "ride_address" = "Sample Address";
    "ride_cover_img" = "uploadfiles/UploadUserImages/2/mobile/21426739600s-end-horton-plains.jpg";
    "ride_id" = 149;
    "ride_name" = "Ride to the World's End";
    "ride_type_id" = 0;
    "ride_type_name" = Travel;
    "ride_user_fname" = Nik;
    "ride_user_id" = 2;
    "ride_user_lname" = Mike;
   }

)

或像这样的代码:

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

一切顺利:)

答案 3 :(得分:0)

正如仅供参考,也可以通过编程方式创建渐变。以下是可用于返回线性渐变的方法示例:

public static GradientDrawable createGradient(int startColor, int endColor, GradientDrawable.Orientation orientation) {
    GradientDrawable returnGradient;

    returnGradient =
            new GradientDrawable(
                    orientation,
                    new int[] {startColor, endColor}
            );

    return returnGradient;
}

并称之为:

int startColor = getResources().getColor(R.color.accent);
int endColor = getResources().getColor(R.color.primary);
GradientDrawable.Orientation orientation = GradientDrawable.Orientation.TOP_BOTTOM;

GradientDrawable gradient = createGradient(startColor, endColor, orientation);

myView.setBackground(gradient);
相关问题