如何在 Android Studio 中的相应 android 设备中获取适当的图像 [英] How to get appropriate images in respective android Device in Android Studio

查看:66
本文介绍了如何在 Android Studio 中的相应 android 设备中获取适当的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计音乐播放器的布局.当我使用 Nexus 5 虚拟设备渲染它时,我根本没有遇到任何问题

当我使用 Nexus 7 渲染图像时,它显示的图像大小相同.

也贴出我的照片截图.

希望能从你们那里得到一些解决方案.

解决方案

你必须按照这个来支持多个设备:

屏幕密度的变化.

xlarge 屏幕至少为 960dp x 720dp大屏幕至少 640dp x 480dp普通屏幕至少为 470dp x 320dp小屏幕至少为 426dp x 320dp

制作此布局文件,以便所有设备都相同.

res/layout/main_activity.xml # 对于手机(小于600dp可用宽度)res/layout-sw600dp/main_activity.xml # 用于 7 英寸平板电脑(600dp 宽和更大)res/layout-sw720dp/main_activity.xml # 适用于 10 英寸平板电脑(720dp 宽和更大)

对于布局 ,

res/layout/my_layout.xml//正常屏幕尺寸的布局(默认")res/layout-large/my_layout.xml//大屏幕布局res/layout-xlarge/my_layout.xml//超大屏幕布局res/layout-xlarge-land/my_layout.xml//横向超大布局

<小时>

对于图片

res/drawable-mdpi/graphic.png//中等密度的位图res/drawable-hdpi/graphic.png//高密度位图res/drawable-xhdpi/graphic.png//超高密度位图res/drawable-xxhdpi/graphic.png//超高密度位图

<小时>

对于图标

res/mipmap-mdpi/my_icon.png//中等密度的启动器图标res/mipmap-hdpi/my_icon.png//高密度的启动器图标res/mipmap-xhdpi/my_icon.png//超高密度的启动器图标res/mipmap-xxhdpi/my_icon.png//超超高密度的启动器图标res/mipmap-xxxhdpi/my_icon.png//超超超高密度的启动器图标

对于启动器图标

36x36 (0.75x) 用于低密度48x48(1.0x 基线)用于中等密度72x72 (1.5x) 用于高密度96x96 (2.0x) 用于超高密度180x180 (3.0x) 用于超高密度192x192 (4.0x) 用于超超超高密度(仅限启动器图标;请参阅上面的注释)

<块引用>

注意: 在处理 textSize 时,请始终尝试使用 SP,例如 textsize=12sp

使用预定义的textAppearance:

它将根据设备密度自动设置文本大小.<TextView android:textAppearance="?android:attr/textAppearanceSmall"/><TextView android:textAppearance="?android:attr/textAppearanceMedium"/><TextView android:textAppearance="?android:attr/textAppearanceLarge"/>示例用法:<文本视图style="@android:style/TextAppearance.Small"android:text="示例文本 - 小"/><文本视图style="@android:style/TextAppearance.Medium"android:text="示例文本 - 中"/><文本视图style="@android:style/TextAppearance.Large"android:text="示例文本 - 大"/>

请访问支持多屏幕

I'm designing the layout of Music Player. When I'm rendering it with the Nexus 5 virtual device, I'm not facing any problem at all

When I render the image with Nexus 7 it is showing the same image size.

Posting screenshot of my photo too.

Hope to get some solution from you guys.

解决方案

You have to follow this to support multiple devices :

changes in screen density.

xlarge screens are at least 960dp x 720dp
large screens are at least 640dp x 480dp
normal screens are at least 470dp x 320dp
small screens are at least 426dp x 320dp

Make this layout files, so that it will be same for all devices.

res/layout/main_activity.xml           # For handsets (smaller than 600dp available width)
res/layout-sw600dp/main_activity.xml   # For 7" tablets (600dp wide and bigger)
res/layout-sw720dp/main_activity.xml   # For 10" tablets (720dp wide and bigger)

For Layout ,

res/layout/my_layout.xml              // layout for normal screen size ("default")
res/layout-large/my_layout.xml        // layout for large screen size
res/layout-xlarge/my_layout.xml       // layout for extra-large screen size
res/layout-xlarge-land/my_layout.xml  // layout for extra-large in landscape orientation


For Images

res/drawable-mdpi/graphic.png         // bitmap for medium-density
res/drawable-hdpi/graphic.png         // bitmap for high-density
res/drawable-xhdpi/graphic.png        // bitmap for extra-high-density
res/drawable-xxhdpi/graphic.png       // bitmap for extra-extra-high-density


For Icon

res/mipmap-mdpi/my_icon.png         // launcher icon for medium-density
res/mipmap-hdpi/my_icon.png         // launcher icon for high-density
res/mipmap-xhdpi/my_icon.png        // launcher icon for extra-high-density
res/mipmap-xxhdpi/my_icon.png       // launcher icon for extra-extra-high-density
res/mipmap-xxxhdpi/my_icon.png      // launcher icon for extra-extra-extra-high-density

For Launcher icon

36x36 (0.75x) for low-density
48x48 (1.0x baseline) for medium-density
72x72 (1.5x) for high-density
96x96 (2.0x) for extra-high-density
180x180 (3.0x) for extra-extra-high-density
192x192 (4.0x) for extra-extra-extra-high-density (launcher icon only; see note above)

NOTE: Always try to use SP whenever you deal with textSize, like textsize=12sp

Use predefined textAppearance:

It will set text size automatically as per device density.

    <TextView android:textAppearance="?android:attr/textAppearanceSmall"/>
    <TextView android:textAppearance="?android:attr/textAppearanceMedium"/>
    <TextView android:textAppearance="?android:attr/textAppearanceLarge" />
Sample usage:

    <TextView
        style="@android:style/TextAppearance.Small"
        android:text="Sample Text - Small" />
    <TextView
        style="@android:style/TextAppearance.Medium"
        android:text="Sample Text  - Medium" />
    <TextView
        style="@android:style/TextAppearance.Large"
        android:text="Sample Text  - Large" />

Please visit Supporting Multiple Screens

这篇关于如何在 Android Studio 中的相应 android 设备中获取适当的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆