Invalid padding setting in Android checkbox solution

Android Check@R_ 518_ Invalid padding setting in 2419 @ solution

Check@R_ 518_ 2419 @ use local picture resources

Check@R_ 518_ 2419 @ is a control used more in Android, but its own button style is ugly, and it is usually replaced with local resource images. Using the local resource image is very simple. Set the Android: button attribute to a custom drawable file containing a selector.

For example, Android: button = "@ drawable / radio"_ style”。 radio_ Style.xml is defined as follows. Checked and unchecked are the image resources used when selected and unchecked respectively.

Check@R_ 518_ 2419 @ Click to respond to questions

When Check@R_ 518_ 2419 @ after using the local picture resources, if the local picture is very small (the picture size needs to be matched with the layout, often too large pictures can not be used for the beauty of the interface) and there is no text on the right, it will lead to Check@R_ 518_ 2419 @ hard to spot. The usual way to increase the click area is to increase the padding value and expand the external range of the control. We hope we can set Check@R_ 518_ The padding value of 2419 @ increases a certain range in the up, down, left and right directions of the picture, so that there will be no problem in the user's response to clicking the picture.

Check@R_ 518_ 2419 @ padding failure

Check@R_ 518_ 2419 @ the actual display effect is shown in the figure after 20dp padding in up, down, left, right and all four directions are set respectively. Here in order to see clearly, for Check@R_ 518_ 2419 @ set the background color and added text.

As can be seen from the diagram, Check@R_ 518_ 2419 @ setting the padding value affects the actual text to Check@R_ 518_ 2419 @ distance from the boundary, the picture is always in the vertical center on the left. First look at the upper and lower padding. When setting the upper and lower padding, because the text itself is a certain distance from the upper and lower boundaries, if the padding value is not set enough, the whole Check@R_ 518_ 2419 @ the area will not change at all. It can be expanded by setting a large padding value Check@R_ 518_ 2419 @ purpose of upper and lower areas. In the last picture, you can see 20dp padding at the top and bottom Check@R_ 518_ 2419 @ height increased. However, due to the distance between the middle text and the upper and lower boundaries Check@R_ 518_ 2419 @ picture height, text font size, text internal padding and many other factors are related. It is difficult to accurately control the setting of up and down padding Check@R_ 518_ 2419 @ area, it is likely that the height is pulled greatly on this mobile phone, but there is no effect on the other mobile phone.

Look at the left and right padding. When setting the left and right padding, whether it is left padding or right padding, it only affects the position of the text. The picture is always on the whole Check@R_ 518_ 2419 @ on the left, for the picture, the increase is the right area. Therefore, the left and right padding settings cannot be solved Check@R_ 518_ 2419 @ the problem of click response will not only lead to the left position of the picture, but also make it impossible to click in the left area.

The problem of invalid padding mentioned in the title is actually effective, but setting paddingleft adds the right area, and the paddingtop and paddingbottom can only see the effect by setting larger values.

Check@R_ 518_ 2419 @ causes of padding failure

If you want to know Check@R_ 518_ 2419 @ the reason for the failure of padding is to check the Android source code, Check@R_ 518_ 2419 @ is inherited from composundbutton, Check@R_ 518_ 2419 @ the picture on the left is drawn in the ondraw() method of the compoundbutton. The ondraw() method code is as follows. Mbuttondrawable is the drawable object corresponding to the picture to be drawn. You can see that the left is always 0, and the top position is related to the grivity (in the above example, the gravity is centered).

solve Check@R_ 518_ 2419 @ Click to respond to questions

because Check@R_ 518_ 2419 @ and compoundbutton do not provide any method to set the position of the picture. Do you want to solve it Check@R_ 518_ 2419 @ it seems that the only way to solve the problem of click response is to rewrite a new control, and then take padding into account when determining the position of the picture in the OnDraw method. But it's too much trouble.

Here is another simple way to expand the picture. Check@R_ 518_ 2419 @ the click response problem itself is because the picture is too small. If you expand the picture, there will be no problem. But as mentioned earlier, the reason why you use small pictures is for layout matching and beautiful interface. If you expand the picture, it will return to the initial problem! In fact, the picture expansion mentioned here does not enlarge the whole picture, but the picture content remains unchanged. Transparent pixels are added around the original picture. Because the transparent pixels are invisible, the actual size of the picture is still the same as before, but due to the existence of transparent pixels, Check@R_ 518_ The area of 2419 @ will also increase.

To add transparent pixels to the picture extranet, the picture must be in PNG format, but this is not a problem. Usually, the resource file is in PNG format. Even if the picture is not in PNG format, it can be converted to PNG format first, and then add transparent pixels.

The method of adding transparent pixels is also very simple. Open the PNG picture in Photoshop, select "image" C "canvas size", and then enter a new size.

If you have any questions, please leave a message or go to the community of this site for exchange and discussion. Thank you for reading. I hope it can help you. Thank you for your support to this site!

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
分享
二维码
< <上一篇
下一篇>>