Sub view automatically moves layout by rules

Source: Internet
Author: User

Before I saw a little flashing on the screen, and moved the interface. At that time to sprout an idea, can make a such choice interface?

Implementation is actually relatively simple, after writing a bit, the feeling can do a good reuse, and easy to expand the mobile rule of view. While the usual time, it simply realized it, and roughly write a few moving rules.

Childautomovilayout Implementing a parent class

Considering that it is easy to use the relativelayout, so use Childautomovilayout as the Relativelayout subclass. So when users are using this layout,
Can be more easily extended. Use margins, for example.

Add Child view mode

Also, because each sub-view can be required to be consistent, because it moves automatically, it is basically some form of view movement. So I use the Android Abslistview adapter as Childautomovilayout
The adapter. Childautomovilayout adds a child view to itself by reading the adapter. Childautomovilayout does not add a view by AddView. This allows the user to implement only one
Adapter can do it. You can even use the adapter of the ListView directly.

Move rule

Move the rule, I design an interface, the user just realizes that interface, and gives childautomovilayout to be able. Setmoviinterface. Move rule takes two methods

        /**                 * 移动                 * @param view                 * @param height 移动高度                 * @param width 移动宽度                 */            void move(View view,int width,int height);            /**                 * 初始化位置                 * @param view                 * @param height 移动高度                 * @param 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 label (subclass view) every 20 milliseconds.

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

# # #xml使用:

            <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>    
Examples of Java code use:
    1. Parse out from XML

      //parse out from XML childautomovilayout    Tagrandomview = (childautomovilayout) Findviewbyid (R.id.tagview);    Final LinearLayout linear = (LinearLayout) Findviewbyid (R.id.tag_container);  
    2. Set adapter and move policy

        final    Tagadapter adapter = new Tagadapter ();    Tagrandomview.setadapter (Adapter, New bubblelineupmoving ());  
    3. The movement of the Listener label (child view)

                           Tagrandomview.setontagclicklistener (New Childautomovilayout.tagclicklistener () {@Override                    public void Ontagclicklistener (view view, int position, long ID) {//todo click things    }            });  
    4. Start animation

           Tagrandomview.startmoving (); 

Child view automatically moves layout by rules

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.