Unwanted padding around an ImageView

前端 未结 8 766
闹比i
闹比i 2020-12-02 05:20

I need to include a header graphic in all of my activities/views. The file with the header is called header.xml:



        
相关标签:
8条回答
  • 2020-12-02 05:32

    You need to provide shape around imageview to give a better look.

    Here what i have used:

    <shape xmlns:android="http://schemas.android.com/apk/res/android">
    <!--<gradient android:startColor="#FFFFFF" android:endColor="#969696"
    
        android:angle="270">
    -->
    <gradient android:startColor="#FFFFFF" android:endColor="#FFFFFF"
    
        android:angle="270">
    </gradient>
        <stroke android:width="2dp" android:color="@color/graycolor" />
    <corners android:radius="2dp" />
    <padding android:left="5dp" android:top="5dp" android:right="5dp"
        android:bottom="5dp" />
    

    0 讨论(0)
  • 2020-12-02 05:33

    use this android:scaleType="fitXY" in imageview xml

    0 讨论(0)
  • 2020-12-02 05:37

    those extra padding is autogenerated since the android would try to get the original aspect ratio. please try below

    scaletype = "fitCenter"
    android:adjustViewBounds="true"
    android:layout_height="wrap_content"
    
    0 讨论(0)
  • 2020-12-02 05:42
    android:layout_height="wrap_content"
    

    You need to change it to "fill_parent"

    You also might need to scale your image so it will be the right ratio to fill the framelayout it is in.

    I don't understand why you need the frame layout there at all. Without it, your image would just fill the screen anyways.

    EDIT: yes, sorry, the xml is the height for the imageview.

    0 讨论(0)
  • 2020-12-02 05:46
    android:scaleType="fitXY"
    

    It works for me.

    0 讨论(0)
  • 2020-12-02 05:47

    finally!

    <ImageView
      (...)
      android:adjustViewBounds="true" />
    

    the adjustViewbounds attribute did the trick:

    Set this to true if you want the ImageView to adjust its bounds to preserve the aspect ratio of its drawable.

    i stumbled upon it here. thanks for your help!

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