Buttons, Image Views, and Image Buttons

1. One button control

1. Inheritance diagram

  • Button is a subclass of TextView

2. Common attributes

Attributes meaning
text text content
textSize Text font size, unit: sp
textColor Text color, #ff0000 - red
background Background color or background image
layout_height Height, unit: dp (wrap_content, match_parent)
layout_weight Width, unit: dp (wrap_content, match_parent)
onClick Click event (used to bind event handling methods)

2. Image view

1. Inheritance diagram

  • ImageView is a subclass of View

2. Common attributes

Attributes meaning
layout_height Height, unit: dp (wrap_content, match_parent)
layout_weight Width, unit: dp (wrap_content, match_parent)
src Source (used to set the image source)
background Background (used to set the background image)
scaleType Scaling type (fitXY)
tint mask

3. Image button

1. Inheritance diagram

  • ImageButton is a subclass of ImageView

2. Common attributes

Attributes meaning
layout_height Height, unit: dp (wrap_content, match_parent)
layout_weight Width, unit: dp (wrap_content, match_parent)
src Source (used to set the image source)
background Background (used to set the background image)

4. Zoom in and out of images via buttons

1. Create an Android application

  • Create an Android app viaEmpty Activity ZoomlamgeByButton
    Insert image description here
  • Click the [finish] button
    Insert image description here

2. Prepare picture materials

  • Add three pictures to the drawable file
    Insert image description here

3. String resource file

  • String resource file -string.xml
    Insert image description here
<resources>
    <string name="app_name">通过按钮缩放图片</string>
    <string name=

Guess you like

Origin blog.csdn.net/m0_63887380/article/details/127737064