Improved –gradient scrims of android– single color gradient effect

Source: Internet
Author: User

This article is based on a g+ +roman Nurik in 2014/11/24. After seeing what he was doing, he was curious, trying to do it according to the method he had proposed, and arranging it to appear directly from the perspective.

In g+ 's text, he suggested a way to improve the gradient that would have looked a little bit, to change the curve to three times, to make it look more smooth, and to be named "gradient scrims". Then, the presentation of this article is still on the Android 5 version can see the best effect OH

First see the results, the following image: The left side is our usual use of habits, right side is the change of the presentation.

On the principle that we have been in the process of Android development, is to use drawable to actually do, in this case, the drawable code is as follows:

1234567891011 <? XML Version="1.0" encoding="Utf-8"?> <selector xmlns:android="Http://schemas.android.com/apk/res/android"> <item> <shape android:shape="Rectangle"> <gradient android:startcolor="@color/primary_dark" android:endcolor="@android: Color/transparent" android:angle="All" /> </shape> </item> </selector>

In the word, it defines a blue-to-transparent, progressively square, and turns it 90 degrees, so that the blue part can be like the left-hand image, which extends from the navigation bar.

This kind of transition is also set in the text block, like the example in this illustration,

123456< /td> <linearlayout    android:layout_width= "match_parent"   android:layout_height= "wrap_content"   android:background= "@drawable/gradlient_background"  

And this is a linear presentation that looks a bit more rigid, so Roman proposed a way to change this line from linear to three curves, and at the same time, to spread this layer of text into this picture of the surface of this. The code for this effect is the scrimutil that will be used in Muzei (this time of the author is not yet used).

And the use of scrim is the most the following:

12345678 if (build.version. Sdk_int >= Android. Os. Build. Version_codes. Jelly_bean { View bottom = findviewbyid(R. ID. View_base_bottom); bottom. SetBackground( scrimutil. Makecubicgradientscrimdrawable( getresources(). GetColor(R. Color. Primary_dark), //color 8, //progressively Gravity. BOTTOM)); //Start direction }

Bottom is a full-screen layout element, which is calculated using the Makecubicgradientscrimdrawable function, and we are going to separate a few gradients in this gradient. Maybe it's because this gradient effect looks like a marl Sleepsac weave, so it's Roman named Gradient scrim. It's all about how many gradients we need to cola.

At the bottom of the three pictures, the left side and the middle of the two maps, are using the Gradient scrim way to appear gradually. The middle of the main is to take off the above the gradient effect, so that the right side of the full line of the line to make a comparison

Supplement: Below these three inserted in the middle of another interface is set, the left side is the original line of the way, the right side is a comprehensive gradient scrims interface;

The newly added middle is the size of the text block, plus the height of the padding, allowing the gradient to focus more on the block.

123456 <linearlayout    Android:id= "@+id /view_base_bottom "   android :layout_width= " Match_parent "   android :layout_height= " Wrap_content "   android :paddingtop= "@ Dimen/gradient_scrim_padding " .

I don't know what kind of people you prefer.

android– modified –gradient scrims (RPM)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.