【问题标题】:How to get appropriate images in respective android Device in Android Studio如何在 Android Studio 中的相应 android 设备中获取适当的图像
【发布时间】:2016-02-10 08:36:09
【问题描述】:

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

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

也发布我的照片截图。

希望能得到你们的一些解决方案。

【问题讨论】:

  • 分享您的 xml 布局并使用不同屏幕尺寸的尺寸
  • 我希望您在每个资源文件夹(例如 ldpi、mdpi、hdpi、xhdpi、xxhdpi)中都有不同的图像屏幕尺寸?如果是,那么问题是您的应用没有为您的设备获取正确的图像
  • 我没有问过这个问题。向提问者提问,看看第一个问题@HirenPatel
  • @Abhishek Dash,能否请您发布gridview的xml行文件
  • 在stackoverflow.com/a/35311502/2826147下方查看这个答案

标签: android android-layout androiddesignsupport android-screen-support mobile-devices


【解决方案1】:

你必须遵循这个来支持多个设备:

屏幕密度的变化。

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

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

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)

对于布局,

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

图片

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

图标

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

对于启动器图标

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)

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

使用预定义的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" />

请访问Supporting Multiple Screens

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-24
    • 2023-01-22
    • 2013-03-15
    • 1970-01-01
    • 2016-03-01
    • 1970-01-01
    相关资源
    最近更新 更多