Android implements the button group instance of the selected commodity size on Taobao

Without much to say, let's start with the last rendering:

Now let's talk about some principles!

1、 Principle:

1. In fact, we use a ViewGroup control group here. Adding these buttons has this effect! However, here we need to inherit some methods in ViewGroup (named: goodsviewgroup) and override them.

2. The main methods are:

The control size of the goodsviewgroup button group

Position coordinates of each button inside

The specific use of these two methods, you can access information online, not much here!

2、 Code:

The above provides some styles for setting the item of the button group, and why should the goodsviewgroup be written as goodsviewgroup < x extensions textview >? In fact, I want to make a generic type here, which can be used with button and textview, and the button here inherits textview, so I need to make a judgment in the code. See the above method setitempadding (x view). When we get here, some friends may ask, why do we have two?

In fact, textview does not automatically set padding, but button does. At this time, you have to see what kind of effect you want first! However, if textview is selected in my code, a padding is also set here, otherwise it will be ugly!

Two modes of writing:

1.Button :

2.TextView

3、 Drawable file: the buttons mentioned above are selected with the normal two drawable files

1.goods_ item_ btn_ normal. xml

2.goods_ item_ btn_ selected. xml

4、 Example:

ButtonGroupActivity

activity_ buttongroup. xml

summary

The above is all about the Android implementation of the button groups of different sizes of Taobao selected products. If there are any questions in this article, you are welcome to point out and make common progress! I hope this article can be helpful to your study and work~

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>