简体   繁体   中英

How to create different layouts for different screens

I have layout with multiple images i want to show them perfectly on every screen size i have created layout-small,normal,large and xlarge also different drawable folders hdpi,mdpi,xhdpi,xxhdpi,ldpi but I am confused that which layout use which dpi folder and what images size should i put on different dpi folders.

Anyone please help me to get out of this problem?

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    android:id="@+id/imageView9"
    android:background="@drawable/main_header"
    android:layout_gravity="center_horizontal"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginLeft="20dp"
    android:layout_marginStart="20dp"
    android:layout_marginTop="20dp" />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:id="@+id/imageView10"
    android:src="@drawable/icon_menu_copy"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="15dp"
    android:layout_toRightOf="@+id/imageView9"
    android:layout_toEndOf="@+id/imageView9" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New Text"
    android:id="@+id/textView"
    android:layout_below="@+id/imageView10"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="69dp" />

Thanks

如果我能理解您的问题,那不是不可以,但是例如在xlarge设备上,您的应用程序随附有layout-xlarge用于布局,xhdpi用于可绘制。

Please make your layout using different values folder in resource. And make only one or two layout for portrait and landscape layouts. Also make different drawable folder for different size of images.

Please also see the link for more details. Mobile Design Practice

Android Studio will choose the suitable dpi for you. So you can put every image you have used in each folder your created in different size but same name. for example:

0.75x drawable-ldpi   (120 dpi, Low density screen)        - 36 x 36px<br/> 
1x    drawable-mdpi   (160 dpi, Medium density screen)     - 48 x 48px<br/> 
1.5x  drawable-hdpi   (240 dpi, High density screen)       - 72 x 72px<br/> 
2x    drawable-xhdpi  (320 dpi, Extra-high density screen) - 96 x 96px<br/> 
3x    drawable-xxhdpi (480 dpi,                         )  - 144 x 144px

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