How can I stretch the image in imagebutton to the whole area of the imagebutton?

前端 未结 7 818
感情败类
感情败类 2021-02-01 18:09

Here is a picture that will help you understand my problem:

\"It's

I want to stretch

相关标签:
7条回答
  • 2021-02-01 18:42

    If your image "111" has no padding itself then simply use android:background"@drawable/111"

    0 讨论(0)
  • 2021-02-01 18:51

    Use below code :-

    <ImageButton
            android:id="@+id/secondActivityBbuttonDownRight"
            android:layout_width="0dip"
            android:layout_height="match_parent"
            android:layout_weight="0.5"
            android:scaleType="fitStart"
            android:background="@drawable/111" />
    
    0 讨论(0)
  • 2021-02-01 18:52

    android:scaleType="fitXY" tested and works correctly.

    0 讨论(0)
  • 2021-02-01 18:54

    You can also use

    android:scaleType="centerCrop"
    android:padding="0dp"
    
    0 讨论(0)
  • 2021-02-01 18:54

    Just set this two attributes on the ImageButton:

    android:background="?attr/selectableItemBackgroundBorderless"
    android:scaleType="centerCrop"
    

    With those, you will get the provided src to be stretched, and also if you put some specific width and height on that ImageButton you won't get a rectangle around it.

    0 讨论(0)
  • 2021-02-01 18:56

    ImageButton is ImageView.
    If you want your image to fill button
    than set android:scaleType="fitXY", so the image you set in android:src will be stretched to fill whole image button.

    ImageButton has a background under your image and padding.
    If you do not want background
    set android:background="@android:color/transparent".
    If you do not want padding
    set android:padding="0" or set background without padding.

    0 讨论(0)
提交回复
热议问题