Android ImageButton Image full fill zoom to control

Source: Internet
Author: User

If you find that you are writing a program like me, you find that the picture cannot be stretched to fill the imagebutton inside. And even if you can zoom to the control, but the image is small, and there will always be a circle around the ImageButton border! You can collect and absorb this experience when you encounter some of these column problems.

The overall process: I first give the key code → analysis of the two solutions → I'll give you a detailed explanation of the reason for the appearance of the border. → Finally, there are some caveats.

Tools/Materials
    • Encounter problems as calmly as possible in the mood.

    • Remember to collect my experience.

    • The length and width of the ImageButton is best fixed. Precautions I'll tell you why

Key code
    1. 1

      The first of these solutions:

      Android:scaletype= "Fitxy"//This code is: stretch the picture (not proportionally) to fill the length of the width. So it's better to be distorted at the end of the image. You have to pay attention.

      Android:background= "#e0000000"//This is a circle border around the image after image scaling is resolved. To make the border transparent to remove the border.

      Second Solution:

      android:src= "@drawable/miss" to android:background= "@drawable/miss" This step replaces the above two steps while resolving the border and full scale padding to the control problem

      The next step is to give you a detailed analysis of a method like full scale padding to a control, and a border after the fill problem

      END
How to scale the fill image to ImageButton
    1. 1

      Android:scaletype= "Fitxy

      Android:scaletype to set how the image is populated

      Fitxy The picture is not scaled up/down to the view size display

      Say something to note:

      In this case, if the aspect ratio of the control is different from the aspect ratio of the image, the distortion is more severe. So pay more attention. Especially when multi-resolution adaptation. Do more real-machine debugging

      This method must be used in conjunction with ANDROID:SRC to populate it. is not valid for Android:background.

    2. 2

      android:src= "@drawable/miss" changed to android:background= "@drawable/miss"

      First background is the property that fills the background. When specified, the extrusion is based on the length width given by the ImageView component.

      The presence of a border is due to the presence of the background. So we can replace the first solution.

      (SRC is the image content (foreground), background is the background and can be used simultaneously.) )

      END
Reasons and solutions for ImageButton with silver-gray border
    1. The reason is that ImageButton default is a border. Or you can say that you set aside a part of the background.

      This will give users a better use of feedback. When clicked, the background will have a color change. is a good integration solution. Of course, for now the development of the interface beautification. So the beauty of the interface, there will be a circle of buttons around the border is too ugly.

      And we usually specify the original image in Src, but Src does not stretch. That's why the border appears.

    2. Solution:

      Android:background= "#e0000000"//This is a circle border around the image after image scaling is resolved. To make the border transparent

      Or you can

      android:src= "@drawable/miss" to android:background= "@drawable/miss

      The first is to make it transparent (in fact android:background= "@null" is also possible)

      The second kind is more straightforward. Change the background directly.

    3. 3

      Well, by the end of this, I'll tell you all about the solutions I've come up with after I've summed up the questions.

      END
Precautions
    • About ImageButton long-width fixation: Because the system will first determine the image width and height. If the control is not fixed and the control is too small relative to the image, it will appear: The system will stretch the control based on the maximum value of the control's length and width (of course, after specifying that the FITXY will not exceed the length and width of the image), and then scale the fill to the control size

      Transferred from: http://jingyan.baidu.com/article/90895e0f97ff7b64ec6b0b1a.html

Android ImageButton Image full fill zoom to control

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.