缩放ImageView在手机和平板电脑上看起来一样 [英] scale ImageView to look the same on phone and tablet
问题描述
这就是在手机和平板电脑上显示图片的方式:
So this is how to image looks on my phone and on my tablet:
我想要缩放图像,以便在平板电脑上打开应用程序时,距离d1,d2,d3,d4与在移动设备上的距离相同.我不希望图片保持相同大小,而只是想按比例缩放,以使我的设计在每台设备上看起来都一样.我尝试使用dp,px来定义距离d1,d2,d3,d4,但是它不起作用.我该怎么办?
I want to scale the image such that when I open the app on tablet, the distances d1,d2,d3,d4 will be the same as they are on mobile. I don't want the picture to stay the same size, I just want it to scale so that my design looks the same on every device. I have tried using dp,px to define the distances d1,d2,d3,d4 but it doesn't work. How can I do this?
推荐答案
一个提供新尺寸单位-sdp(可缩放dp)的android SDK.此大小单位与屏幕大小成比例.它可以帮助Android开发人员支持多个屏幕.
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.
越过这个库:
dependencies {
implementation 'com.intuit.sdp:sdp-android:1.0.5'
implementation 'com.intuit.ssp:ssp-android:1.0.5'
}
如果要使用height
,width
,margin
,padding
等,请使用 @dimen/_20sdp
. (按照您的要求选择大小).
If you want to use height
, width
, margin
, padding
etc then you use @dimen/_20sdp
. (Take Size as per your requirement).
如果要使用TextSize
,请使用 @diment/_12ssp
. (根据您的要求选择尺寸).
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
-
sdp
用于平板电脑和移动设备中的相同UI. -
ssp
用于平板电脑和移动设备的相同TextSize.
您还可以在另一个示例中看到此链接: https://github.com/intuit/sdp
also u can see this link for another example: https://github.com/intuit/sdp
希望它对您有用
这篇关于缩放ImageView在手机和平板电脑上看起来一样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!