Android development of the magical fading Edge, let your view more layered sense!

Source: Internet
Author: User

Recently in the study of the Android framework layer source code, found that our understanding of the source code should be based on the understanding of the API, if there are some APIs you have not used, then even if you see in the source of this thing do not know what to do, not to mention understand. I have always wanted to draw a detailed view of the drawing method, but the details of the problem here is too much, so today we still first look at fading Edge, for the draw method to continue to lay the groundwork.

Before this blog, I have launched five articles on view painting, I believe these five blog will help you understand this blog.

1.View drawing in detail, from Layoutinflater

2.View Drawing in detail (ii) from Setcontentview

3.View Drawing in detail (iii), grilled a grilled view of the measurement process

4.View Drawing in detail (iv), boaster a boaster layout process

5.View Drawing Details (v), Draw method detailed detailed view of the rolling/sliding problem


Why do you say fading Edge? This is not very much in our usual development of the API is actually the view drawing process an important step, bypassing the threshold! But to understand the source code, we have to know this fading edge in the end is what? From the literal understanding, this is to achieve the edge gradient effect, OK, then we first look at:

Here I take a rolling texview as an example, the small partners see the effect of this shadow. Fading edge can also be used on a ListView, with similar effects. OK, so let's start by looking at how this effect is achieved.

In general, in order to achieve textview scrolling effect, many small partners first think of the method may be nested in ScrollView a textview, but in fact, do not do this we can still achieve textview scrolling effect, Let's take a look at how the scroll effect of the blue TextView above is implemented:

    <textview        android:id= "@+id/tv"        android:layout_width= "match_parent"        android:layout_height= "128DP "        android:background=" @color/colorprimary "        android:fadingedgelength=" 50DP "        android: Requiresfadingedge= "vertical"        android:text= "@string/content"/>

Fadingedgelength represents the height of the shaded portion, and Requiresfadingedge represents the direction of the shadow. The direction can be horizontal or vertical. Horizontal effect I'll talk about it a minute later. Of course, if we just write this in the XML file, TextView still can't scroll, and we need to add the following line of code to the activity, TextView can scroll up as follows:

Tv.setmovementmethod (New Scrollingmovementmethod ());

Of course, we can also use ScrollView to let TextView roll up, this time just add fading edge related properties to ScrollView:

    <scrollview        android:layout_width= "match_parent"        android:layout_height= "128DP"        android:layout_ margintop= "20DP"        android:fadingedgelength= "50DP"        android:requiresfadingedge= "vertical" >        < TextView            android:layout_width= "match_parent"            android:layout_height= "72DP"            android:scrollbars= " Vertical "            android:text=" @string/content "/>    </ScrollView>

The meaning of the related attribute don't say it again!

OK, then let's look at a horizontal effect:

At the end of the day, the color of the word fades until it disappears. OK, so how can this effect be achieved? See below:

    <textview        android:id= "@+id/tv"        android:layout_width= "match_parent" android:layout_height= "Wrap_        Content "        android:singleline=" true "        android:ellipsize=" None "        android:background=" @color/ Colorprimary "        android:fadingedgelength=" 200DP "        android:requiresfadingedge=" Horizontal "        android: text= "@string/content"/>

OK, in addition, let's take a look at the use of fading edge in the ListView. Let's take a look:


In fact, in the fading edge use, this effect in the ListView is one of the easiest to implement, we take a look at the code:

    <listview        android:id= "@+id/lv"        android:layout_width= "match_parent"        android:layout_height= "match _parent "        android:fadingedge=" vertical "        android:fadingedgelength=" 200DP "        Android:requiresfadingedge = "Vertical" ></ListView>

Data binding is the normal way to bind, not to repeat.


OK, this is a simple use of fading edge in our view, which is recorded first and lays the groundwork for a comprehensive analysis of the draw method behind it.



Above.



Android development of the magical fading Edge, let your view more layered sense!

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.