Step-by-step implementation of GIF animation dropdown (one)

Source: Internet
Author: User

Pre-reprint marked: http://blog.csdn.net/yoyo_newbie/article/details/47167933

Don't blow it, go straight to the subject.

The first step is to implement the combination of the head and the content first. Inherit the LinearLayout and let its 2 be arranged in a linear order. Inheriting LinearLayout benefits can extend a variety of pull-down, such as the ListView dropdown, the GridView drop-down, or the waterfall that can be implemented by the recycler.

1. This demo is a GIF play open Source Library and Recyclerview implementation, need to join the Open Source Library. In the app directory, add the following builder-gradle

Dependencies {    compile filetree (include: [' *.jar 'dir' Libs ')    ' COM.FELIPECSL: gifimageview:1.2.0'com.android.support:recyclerview-v7:22.2.0 '}    

Create a new drop-down drawing header file for Refresh_list_header, with the following details:


<?XML version="1.0"encoding="Utf-8"?><linearlayoutxmlns:Android="Http://schemas.android.com/apk/res/android"    Android: Layout_width="Match_parent"    Android: layout_height="Wrap_content"    Android: background="#000000"    Android:p adding="8DP"    Android: gravity="Center"><com.felipecsl.gifimageview.library.gifimageview        Android: id="@+id/gf_image"        Android: Layout_width="Match_parent"        Android: layout_height="Wrap_content"        Android: src="@mipmap/gif_nv2"        /></LinearLayout>

Dynamic graphs:

Gif_nv2.gif



And then start writing. Drop-down component. Since in order to extend a variety of pull-down, we write a base class that supports multiple scenarios.


/*** with GIF under Laki class */Public abstract classbasegifrefresh<VextendsView>extendslinearlayout{/*** Content Section     */    PrivateVChilderview;protected AbstractVGetconvertview(Context context); PublicBasegifrefresh (Context Context, AttributeSet attrs) {Super(Context, ATTRS);        Init (context);    }/*** Refresh time, show the head     */    PrivateViewHeanderview;    /*** Initialize UI     * @paramContext     */    private voidInit(Context context) {//Set Vertical layout        SetOrientation (LinearLayout.VERTICAL);        //Add head        Heanderview= Newheaderview (context);        AddView (Heanderview);        //Add Content section        Childerview= Newchildview (context);        AddView (Childerview);    }/*** Construct a head header     * @paramContext     * @return     */    PrivateViewNewheaderview(Context context) {View Heanderview = Layoutinflater. from(context). Inflate (r.layout.Refresh_list_header, NULL);        Linearlayout.layoutparams Headerviewparams =NewLinearlayout.layoutparams (Layoutparams.match_parent,  Layoutparams.wrap_content);        Heanderview.setlayoutparams (Headerviewparams);returnHeanderview;    }/*** Component Content Section     * @paramContext     * @return     */    PrivateVNewchildview(Context context) {Linearlayout.layoutparams Convertviewparams =NewLinearlayout.layoutparams (Layoutparams.match_parent,  Layoutparams.match_parent);        Convertviewparams.Weight=1;        VChildview = Getconvertview (context);        Childview.setbackgroundcolor (Color.RED);//TODO to see the effect, test it, occupy the red part of the content        Childview.setlayoutparams (Convertviewparams);returnChildview;    }}

Then write a dropdown for the support list. such as the linear list, we use Recyclerview to do the example

/*** The ListView that drives the drawing head */Public classGifrefreshlistviewextendsbasegifrefresh<recyclerview>{@Override    protectedRecyclerviewGetconvertview(Context context) {Recyclerview Recyclerview =NewRecyclerview (context);        Linearlayoutmanager Linearlayoutmanager =NewLinearlayoutmanager (context);        Linearlayoutmanager.setorientation (Linearlayoutmanager.VERTICAL);        Recyclerview.setlayoutmanager (Linearlayoutmanager);returnRecyclerview;    } PublicGifrefreshlistview (Context Context, AttributeSet attrs) {Super(Context, ATTRS);    }}




Write a Mainactivity.java

    @OverrideonCreate (Bundle savedinstancestate) {super.             OnCreate (savedinstancestate);          Setcontentview (r.layout.  Activity_main);    


Activity_main.xml

<relativelayoutxmlns:Android="Http://schemas.android.com/apk/res/android"     Android: Layout_width="Match_parent"    Android: layout_height="Match_parent"    ><sam.widget.gifrefreshlistview        Android: id="@+id/listview"        Android: Layout_width="Match_parent"        Android: layout_height="Match_parent"/></RelativeLayout>



For






This GIF has not yet been used by the playback API, so it is static





Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Step-by-step implementation of GIF animation dropdown (one)

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.