Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
273 views
in Technique[技术] by (71.8m points)

android - scale ImageView to look the same on phone and tablet

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 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...