简体   繁体   English

如何为不同的屏幕创建不同的布局

[英]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. 我有多个图像的布局,我想在每个屏幕尺寸上完美显示它们,我创建了布局-小,普通,大和xlarge以及不同的可绘制文件夹hdpi,mdpi,xhdpi,xxhdpi,ldpi,但我对哪个布局使用哪个感到困惑dpi文件夹以及应在不同的dpi文件夹上放置多少图像大小。

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. 还要为不同尺寸的图像设置不同的drawable文件夹。

Please also see the link for more details. 另请参阅链接以获取更多详细信息。 Mobile Design Practice 移动设计实践

Android Studio will choose the suitable dpi for you. Android Studio将为您选择合适的dpi。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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