scale ImageView to look the same on phone and tablet

后端 未结 2 520
感动是毒
感动是毒 2020-12-07 05:56

So this is how to image looks on my phone and on my tablet:

phone

tablet

I want to scale the image such that when I open the app on tablet, the dista

相关标签:
2条回答
  • 2020-12-07 06:35

    An android SDK that provides a new size unit - sdp (scalable dp). This size unit scales with the screen size. It can help Android developers with supporting multiple screens.

    in gradle past this library :

    dependencies {
      implementation 'com.intuit.sdp:sdp-android:1.0.5'
      implementation 'com.intuit.ssp:ssp-android:1.0.5'
    }
    

    If you want to use height, width, margin, padding etc then you use @dimen/_20sdp. (Take Size as per your requirement).

    If you want to use TextSize then use @diment/_12ssp. (Take Size as per your requirement).

    Please have a look below sample code:

    <ImageView
                android:id="@+id/img_companies"
                android:layout_width="@dimen/_20sdp"
                android:layout_height="@dimen/_20sdp"
                android:src="@drawable/ic_companies"
                android:layout_gravity="center_vertical"
                android:layout_weight="1"/>
    

    this way u can use fix size of height and width both side

    UPDATE

    • sdp is used for same UI in Tablet and Mobile devices.
    • ssp is used for same TextSize for Tablet and Mobile devices.

    also u can see this link for another example: https://github.com/intuit/sdp

    hope it's useful for u

    0 讨论(0)
  • 2020-12-07 06:54

    I think may be you may set the width and height of the image view to match parent then you may add margins (left,right,top and bottom) according to d1,d2,d3 and d4 then set the scale type of the image view to fit xy.....I am not so sure of the last step but I think I will work

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