简体   繁体   中英

Design Custom Android ViewGroup Subclasses

Android Developer has a nice discussion on writing your own View subclasses: http://developer.android.com/guide/topics/ui/custom-components.html

But I want to write my own ViewGroup subclass with my own child positioning policy. Where is there a minimal example of this kind of thing? (This is a Java coding question not an XML one)

Specifically I want a horizontal layout that (like LinearLayout) fills in children from the left - but once the horizontal space is consumed, shifts the children to the left so that the last child appears aligned to the right end of the layout. The children are button-like and so a HorzontalScrollView does not work since the scrolling gesture clicks the buttons instead of moving them.

If LinearLayout has an option to do this, I could not find it.

HorizontalScrollView should work, scrolling should not click the buttons. But if you really want to write your own custom layout, have a look at this archive (the video is also available)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM