Android的哪个部分负责挑选一个正确的资源配置文件? [英] Which part of Android is in charge of picking a correct resource profile?

查看:247
本文介绍了Android的哪个部分负责挑选一个正确的资源配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题。

在你来一个想法,骂我,我工作的一个自定义的果冻豆。因此,通常不错的办法可能不会在这里工作,和肮脏的解决方法已经作出。

Before you come to an idea to lash out on me, I am working on a custom Jelly Bean. Therefore the "usual nice approaches" might not work here, and dirty workarounds have to be made.

我有一个包含一个APK资产如下:

I have an APK which contains the following in assets:

layout
layout-mdpi
layout-land
layout-large-mdpi
layout-large-land-mdpi
layout-large-hdpi
layout-large-xhdpi

和其他一些指标code返回这样的:

And some other metrics code returned this:

D/AppDemo( 2091): measured width: 1920 PE width: 1920 scaleFactor = 1.0
D/AppDemo( 2091): [ANDROID] measured width: 1920 measured height: 1080
D/AppDemo( 2091): [ANDROID] scale for resources: 2.0 xdpi: 320.0 ydpi: 320.0
D/AppDemo( 2091): [ANDROID] screen density: xhdpi
D/AppDemo( 2091): [ANDROID] screen size: large
D/AppDemo( 2091): [ANDROID] using layout: layout-mdpi

所以,看的指标,为什么不布局大xhdpi 正装?

请告诉我在哪里我可以看看这件事。我真的需要找到一种方法来强制布局/资源/ AssetManager 加载特定的布局。

Please, tell me where I can look this up. I really need to find a way to force the Layout/Resource/AssetManager to load a specific layout.

我知道在这个问题上最流行的评论是你不需要/你为什么有布局xhdpi ,你应该有绘制-xhdpi 布局大,但是,忍耐一下。

I am aware the most popular comment on this issue is "you do not need / why do you have layout-xhdpi, you should have drawable-xhdpi and layout-large" but, bear with me.

我会非常AP preciate哪怕是很小的提示到哪里看,并寻找什么。到目前为止, AssetManager 好像开始挖的地方/日志。

I would very appreciate even small hints as to where to look at, and what to look for. So far, AssetManager seems like the place to start digging/logging.

当我忽略布局MDPI ,在我的应用程序崩溃,缺失的资源。这个错误似乎是,即使code返回 xhdpi ,它假定 MDPI 别的地方。我需要找到这一点,解决它,所以我的应用程序看起来像他们那样对ICS的那样好:)

When I omit layout-mdpi, the application crashes on me, with missing resources. The bug seems to be that even though the code returns xhdpi, it assumes mdpi somewhere else. I need to find this, and fix it so my apps look as nice as they did on ICS :)

我搞清楚它的布局是在一个简单的方式加载 - 所有根布局有一个安卓标签元素,当我的setContentView( R.layout.main_layout)我抢根元素的标签,知道得到装载哪个文件夹。除了视觉反馈,这将最终要配合我的设备配置。

I am figuring out which layout is loaded in a simple manner - all root layouts have a android:tag element, and when I setContentView(R.layout.main_layout) I grab the tag on the root element and know which folder got loaded. Apart from the visual feedback, this will eventually have to match with my device configuration.

在此先感谢。

推荐答案

有趣的问题。我一看,这一切都有点下降了兔子洞。没有答案,因为这样,但也许我的分析将设置你在正确的方向。

Interesting problem. I had a look, but it all goes a bit down the rabbit hole. No answer as such, but maybe my analysis will set you in the right direction.

我看着从的setContentView 转发发生了什么事。显然,在这一点上,你所谈论的密度无关布局职权范围(如 R.layout.main_layout ),然后后它会变成一个引用到一个特定的文件中的APK。何时何地是你的问题。

I looked at what happened from setContentView forwards. Obviously at that point you are talking in terms of a density-agnostic layout reference (e.g. R.layout.main_layout) and then later it will be turned into a reference to a specific file in the APK. When and where is your question.

我用横向/纵向预选赛,这样我可以更改质量在运行时,我用了Android源代码调试器连接。

I used landscape/portrait qualifiers so that I could change the quality at runtime, and I used a debugger with the Android source attached.

下面是一个流程,从某种方式进去。

Here's a flow, starting some way into it.

  1. Resources.getLayout(INT)
  2. Resources.loadXmlResourceParser(INT,字符串)
  3. Resources.getValue(INT,的TypedValue,布尔)
  4. AssetManager.getResourceValue(INT,INT,的TypedValue,布尔)
  5. StringBlock.get(INT)
  6. StringBlock.nativeGetString(INT,INT)

让我们携手倒退。

第六步是原生的(C)方法返回限定引用,如 /res/layout-land/yourview.xml 。它的参数是一个指标,但是,这种变化的基础上,我们无论是在横向或纵向。

Step 6 is a native (C) method that returns the qualified reference, e.g. /res/layout-land/yourview.xml. Its parameter is an index, however, and this changes based on whether we are in landscape or portrait.

要看到的是来自我们必须回到步骤4。该指数是的TypedValue中的一个字段,但它不是初始设置正确时,它会被传递给此方法。

To see where that came from we have to go back to step 4. The index is a field within the TypedValue, but it is not initially set correctly when it is passed in to this method.

步骤4调用另一个本地方法, AssetManager.loadResourceValue(),它改变了传递的TypedValue,并设置适当的索引。

Step 4 calls another native method, AssetManager.loadResourceValue(), which alters the passed in TypedValue and sets the index appropriately.

也许你可以开始寻找下进行的,看看你的身体情况如何。

Maybe you can start looking at the C for that and see how you get on.

这篇关于Android的哪个部分负责挑选一个正确的资源配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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