The sub-View automatically moves Layout according to the rule, and the view moves layout

Source: Internet
Author: User

The sub-View automatically moves Layout according to the rule, and the view moves layout

Project address: https://github.com/xxxzhi/ChildAutoMovi-Layout

Previously, I saw a page that was flashing and moving. At that time, I came up with an idea. Can I make such a selection interface?

The implementation is actually relatively simple. After writing it, I feel that I can make a View that can be reused well and easily expand the mobile rule. At ordinary times, we simply implemented it and roughly wrote several mobile rules.

ChildAutoMoviLayout implements the parent class

Given that RelativeLayout is easier to use, ChildAutoMoviLayout is used as a subclass of RelativeLayout. In this way, when you use this Layout,
It can be expanded more conveniently. For example, use Margins.

Add a subview

In addition, because each sub-View can be consistent, because automatic movement basically involves some similar forms of View movement. So I use the Adapter of Android AbsListView as ChildAutoMoviLayout.
. ChildAutoMoviLayout adds a subview to the Adapter by reading the Adapter. ChildAutoMoviLayout does not use addView to add a View. In this way, you only need to implement one
Adapter. You can even use the ListView Adapter directly.

Mobile rule

For a mobile rule, I design an interface. You only need to implement that interface and give it to ChildAutoMoviLayout. SetMoviInterface. Two methods are used for moving rules.

/*** Move ** @ param view * @ param height move height * @ param width move width */void move (View view, int width, int height ); /*** initialization position ** @ param view * @ param height move height * @ param width move width */void init (View view, int width, int height );
Animation implementation

I use TimeTask as a timer, and then use the timer to move a middle-class tag (subclass view) every 20 milliseconds)

    timer.scheduleAtFixedRate(timerTask, 1000, 20);
Introduction

### Xml usage:

            <com.houzhi.childautomovi.view.ChildAutoMoviLayout                android:id="@+id/tagView"                android:layout_below="@+id/tag_container"                android:layout_width="match_parent"                android:layout_height="match_parent">                </com.houzhi.childautomovi.view.ChildAutoMoviLayout>    
Java code example:

Project address: https://github.com/xxxzhi/ChildAutoMovi-Layout

Related Article

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.