有没有办法确定当前设备的屏幕尺寸类别,如小,普通,大,xlarge?
不是密度,而是屏幕尺寸.
在Android中支持不同的屏幕尺寸(密度)时,通常关注的是为每个可能的屏幕创建不同的布局.IE
我为xhdpi屏幕设计了一个布局作为参考,并在dimens.xml中定义了它的尺寸.现在我想支持每个可能的屏幕尺寸.我怎样才能做到这一点?
据我所知,我可以使用此工具找出适合其他屏幕尺寸的dimens.xml并将其添加到我的项目中.这是在我的情况下这样做的正确方法吗?
另一个问题,我是否只需要为上面的屏幕尺寸创建dimens.xml?如果是,那么是什么w820dp?
谢谢你的帮助.我只需要支持手机(不是平板电脑或其他设备).
android android-layout android-screen-support android-activity
我需要澄清一些关于我的应用程序的图像资产的疑问,
如果我在xml文件中指定某事物[图像视图]的高度为50倾角高度
我应该从资源文件夹中选择哪种类型的屏幕?
drawable, hdpi, ldpi, mdpi, xhdpi,
Run Code Online (Sandbox Code Playgroud)
拥有50像素高度的图像,
与基本图像相比,更大,更小尺寸图像的百分比是多少,
就像在iOS中一样,@ 2x,实际上是图像大小的2倍,并且以编程方式表示正常大小,
谢谢!
android android-image android-screen-support android-resources
根据http://developer.android.com/training/multiscreen/screendensities.html
提到了以下比例因子
xhdpi:2.0 hdpi:1.5 mdpi:1.0(基线)ldpi:0.75
我想知道xxhdpi的比例因子是什么?
我真的很困惑.从developer.android.com上的文档来看,为了保持我的图像在所有当前Android设备上正确缩放(宽高比),我需要以下所有这些布局.这真的是每个人都在做什么?我错过了什么,或者我应该以不同的方式解决这个问题?
Run Code Online (Sandbox Code Playgroud)Low density Small screens QVGA 240x320 ------------------------------------------------ layout-small-ldpi layout-small-land-ldpi Low density Normal screens WVGA400 240x400 (x432) ------------------------------------------------ layout-ldpi layout-land-ldpi Medium density Normal screens HVGA 320x480 ------------------------------------------------ layout-mdpi layout-land-mdpi Medium density Large screens HVGA 320x480 ------------------------------------------------ layout-large-mdpi layout-large-land-mdpi High density Normal screens WVGA800 480x800 (x854) ------------------------------------------------ layout-hdpi layout-land-hdpi Xoom (medium density large but 1280x800 res) ------------------------------------------------ layout-xlarge layout-xlarge-land
我遇到的问题表明,为给定活动的layoutXML 选择的资源桶与从values文件夹中选择的资源不一致,尽管在每组文件夹中使用完全相同的资源限定符.
在我的应用程序的抽象父活动中放置一些日志代码后,我可以看到,当通过Nexus 7类型模拟器(Android 4.1)启动我的应用程序时,最小宽度确实是600dp,该layout-sw600dp-*文件夹用于获取活动的UI但是用于valuesis的文件夹values-large-*.我希望这能values-sw600dp-*为我提供关于活动所运行的资源桶的重要信息.
代码在我的应用程序的父活动中记录所有android.app.Activitys
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Configuration config = getResources().getConfiguration();
Log.i(this.getClass().getSimpleName(), String.format("Smallest width is [%s]", config.smallestScreenWidthDp));
configurationContext = SupportedDeviceConfiguration.fromResourceQualifer(getString(string.resourceQualifier));
Log.i(this.getClass().getSimpleName(), String.format("Running under the [%s] configuration context.", configurationContext.getResourceQualifier()));
...
Run Code Online (Sandbox Code Playgroud)
记录在Nexus 7类型设备上运行此代码时的输出;
[Logging fluff] Smallest width is [600]
[Logging fluff] Running under the [layout-large-land] configuration context.
Run Code Online (Sandbox Code Playgroud)
我知道你在想什么 - 那个布局大片土地的衍生来自哪里?继续阅读......
我正在试验这里概述的方法,这将允许我在运行时检查正在使用的资源桶.基本上我实现的方法具有以下资源限定符结构;
- res …Run Code Online (Sandbox Code Playgroud) android android-layout android-screen-support android-resources
对于我需要在我的应用中使用的每个图标,我有4种不同的尺寸.问题是My Nexus 7(1280 x 800)和galaxy s2(800 x 480)似乎使用drawable-hdpi中的资源.如何强制Nexus在drawable-xhdpi中使用资源,然后使用10英寸选项卡使用drawable-xxhdpi.
我在我的清单文件中有这个
<supports-screens android:resizeable="true"
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
Run Code Online (Sandbox Code Playgroud) android android-manifest android-screen android-screen-support android-drawable
最近的博客解释说我们必须使用
<meta-data android:name="android.max_aspect" android:value="2.1" />
Run Code Online (Sandbox Code Playgroud)
在AndroidManifest.xml的<application>元素中,可在超宽屏设备上实现最佳显示效果,例如Samsung Galaxy S8.
为了验证这一点,我安装我的应用程序(不max_aspect,没有resizeableActivity标志; targetSdkVersion=22,compileSdkVersion=24)在Android 7.1.1.仿真器具有自定义2960x1440分辨率.所有活动,包括身临其境,填充屏幕没有边距,如博客文章中所示.
我明确地补充道
<meta-data android:name="android.max_aspect" android:value="1.5" />
Run Code Online (Sandbox Code Playgroud)
这对模拟器也没有影响.
所以,问题是:这个元标志只在真实设备上检查过,还是我的模拟器错过了一些配置?
更新:我试图联系引用博客文章的作者Neto Marin.我发现了一条引以为傲的推文
关于他对全球Android Dev社区的贡献,但无法得到他的回答.
我开发了一个应用程序,现在我想限制平板电脑的应用程序.
表示应用程序不应在任何平板电脑上运行.为此我在Androidmenifest.XML文件中指定支持屏幕为:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.abc.xyz"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="5"
android:targetSdkVersion="17"
android:maxSdkVersion="17" />
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="false"
android:xlargeScreens="false"
android:resizeable="true"
android:anyDensity="true" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:icon="@drawable/appicon"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:allowBackup="true" >
<activity
android:name="com.abc.xyz.activities.hello"
android:label="@string/title_activity_hello" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
现在的问题是:
应用程序在平板电脑上运行
android:largeScreens="false"
android:xlargeScreens="false"
Run Code Online (Sandbox Code Playgroud)
在宣布上述之后.
那我该怎么办 请建议我并指导我.
android android-manifest android-screen android-screen-support
我有4种不同的设备:
我想知道我的设备的最小宽度(sw)为它做一个支撑布局.
我想创建一个像"layout-sw600dp"这样的资源文件夹,但我不知道最小宽度(sw)的值.
我尝试使用以下代码打印sw:
DisplayMetrics metrics = getResources().getDisplayMetrics();
Log.i("Density", ""+metrics.densityDpi);
Run Code Online (Sandbox Code Playgroud)
但我不知道这是否是正确的价值.
如何找到最小宽度(sw)?