简体   繁体   中英

An ImageView that keep the size of 4cm on all devices?

I have an Image view with pictures in it (they are all the exact same size) and the image view should keep it's size over all devices, htc, sony, samsung, and so on. it's not important which exact size, it should be between 3.8x3.8 cm and 4.5x4.5 cm. that means, if I'll take a scale and measure the size on screens of different devices, it should be always the same numbers.

xml:

<RelativeLayout
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
         >

       <ImageView
           android:id="@+id/testanzeige"
           android:layout_centerHorizontal="true"
           android:layout_centerVertical="true"
           android:src="@drawable/info" 
         android:layout_width="231dp"
            android:layout_height="231dp"/>

look at More Resource Types

There is a unit called mm for Millimeters. (10mm are equal to 1cm)

mm Millimeters - Based on the physical size of the screen

in your case you just use 40mm x 40mm .

<ImageView
       android:id="@+id/testanzeige"
       android:layout_centerHorizontal="true"
       android:layout_centerVertical="true"
       android:src="@drawable/info" 
       android:layout_width="40mm"
       android:layout_height="40mm"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM