android - 转储的 XML 布局文件填充位置行为不正确

标签 android

我一直在努力弄清楚如何理解转储的 XML 布局,并且进展“相当不错”。我目前唯一不确定的是以下内容:

当我使用命令时:

aapt dump xmltree <pathofapk> <pathofxmlfile>

我得到以下结果:

   N: android=http://schemas.android.com/apk/res/android
  E: LinearLayout (line=2)
    A: android:orientation(0x010100c4)=(type 0x10)0x1
    A: android:layout_width(0x010100f4)=(type 0x10)0xffffffff
    A: android:layout_height(0x010100f5)=(type 0x10)0xffffffff
    E: LinearLayout (line=7)
      A: android:orientation(0x010100c4)=(type 0x10)0x0
      A: android:background(0x010100d4)=@0x7f020004
      A: android:layout_width(0x010100f4)=(type 0x10)0xffffffff
      A: android:layout_height(0x010100f5)=(type 0x10)0xfffffffe
      E: ImageView (line=12)
        A: android:gravity(0x010100af)=(type 0x11)0x3
        A: android:layout_gravity(0x010100b3)=(type 0x11)0x13
        A: android:id(0x010100d0)=@0x7f090021
        A: android:paddingLeft(0x010100d6)=(type 0x5)0xa01
        A: android:paddingTop(0x010100d7)=(type 0x5)0x401
        A: android:layout_width(0x010100f4)=(type 0x10)0xfffffffe
        A: android:layout_height(0x010100f5)=(type 0x10)0xfffffffe
        A: android:src(0x01010119)=@0x7f020006
    E: ScrollView (line=21)
      A: android:orientation(0x010100c4)=(type 0x10)0x1
      A: android:layout_width(0x010100f4)=(type 0x10)0xffffffff
      A: android:layout_height(0x010100f5)=(type 0x10)0xffffffff
      A: android:layout_weight(0x01010181)=(type 0x4)0x3f800000
      E: LinearLayout (line=25)
        A: android:orientation(0x010100c4)=(type 0x10)0x1
        A: android:id(0x010100d0)=@0x7f09002d
        A: android:padding(0x010100d5)=(type 0x5)0xa01
        A: android:layout_width(0x010100f4)=(type 0x10)0xffffffff
        A: android:layout_height(0x010100f5)=(type 0x10)0xffffffff
        E: EditText (line=29)
          A: android:layout_gravity(0x010100b3)=(type 0x11)0x51
          A: android:id(0x010100d0)=@0x7f09002e
          A: android:layout_width(0x010100f4)=(type 0x10)0xffffffff
          A: android:layout_height(0x010100f5)=(type 0x10)0xfffffffe
          A: android:text(0x0101014f)="" (Raw: "")
          A: android:hint(0x01010150)=@0x7f070050
        E: EditText (line=36)
          A: android:layout_gravity(0x010100b3)=(type 0x11)0x51
          A: android:id(0x010100d0)=@0x7f09002f
          A: android:layout_width(0x010100f4)=(type 0x10)0xffffffff
          A: android:layout_height(0x010100f5)=(type 0x10)0xfffffffe
          A: android:text(0x0101014f)="" (Raw: "")
          A: android:hint(0x01010150)=@0x7f070051
          A: android:password(0x0101015c)=(type 0x12)0xffffffff
        E: LinearLayout (line=44)
          A: android:orientation(0x010100c4)=(type 0x10)0x0
          A: android:padding(0x010100d5)=(type 0x5)0xa01
          A: android:layout_width(0x010100f4)=(type 0x10)0xffffffff
          A: android:layout_height(0x010100f5)=(type 0x10)0xfffffffe
          E: Button (line=48)
            A: android:id(0x010100d0)=@0x7f090030
            A: android:layout_width(0x010100f4)=(type 0x10)0xffffffff
            A: android:layout_height(0x010100f5)=(type 0x10)0xfffffffe
            A: android:text(0x0101014f)=@0x7f07000a
            A: android:layout_weight(0x01010181)=(type 0x4)0x3f800000
          E: Button (line=54)
            A: android:id(0x010100d0)=@0x7f090031
            A: android:layout_width(0x010100f4)=(type 0x10)0xffffffff
            A: android:layout_height(0x010100f5)=(type 0x10)0xfffffffe
            A: android:text(0x0101014f)=@0x7f070003
            A: android:layout_weight(0x01010181)=(type 0x4)0x3f800000

这一切都很好,但我想弄清楚的是如何将以下代码转换为 XML 布局文件:

    A: android:paddingLeft(0x010100d6)=(type 0x5)0xa01
    A: android:paddingTop(0x010100d7)=(type 0x5)0x401

将这些值转换为十进制将导致:

paddingLeft:2561
paddingTop:1025

很好,但我一直在试图弄清楚(类型 0x5 的含义)。对于所有其他类型,结果在 Android.util.TypedValue.class 文件中定义

对其进行反编译,得到以下 0x5 的结果:

      // Field descriptor #8 I
  public static final int TYPE_DIMENSION = 5;

在某种程度上是有道理的。但是,我需要知道它是什么样的值,所以往下看,我发现了以下值:

  // Field descriptor #8 I
  public static final int COMPLEX_UNIT_MM = 5;

但是,当我尝试使用 2561 毫米和 1025 毫米时(无论如何,25 厘米……比我的屏幕大),整个屏幕都充满了“父 LinearLayout”。

我不知道哪里出了问题。任何人都可以在这个问题上启发我吗?

最佳答案

这些类型值的数据结构在此处定义:

https://android.googlesource.com/platform/frameworks/base/+/gingerbread-release/include/utils/ResourceTypes.h#220

里面是类型代码的枚举;之后是分数和单位类型的位定义。 (您在这里看到的是单位类型——即 20sp。)

关于android - 转储的 XML 布局文件填充位置行为不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1979679/

相关文章:

android - cordova:为内容 src 打开的外部浏览器

java - 从多次出现的较大字符串中获取特定的小字符串

android - AudioFlinger 无法创建效果,状态 : -22

安卓 4.0.3 ScrollingTabContainerView NullPointerException

java - 根据设备功能自定义线程的最佳方法是什么

java - 尝试使用 ProGuard 混淆导出 apk 时出现 "Out Of Memory"

java - 在Java/Android中使用套接字多次发送二进制数据

android - 在android中添加横向方向和代码的最简单方法

java - 禁用在 ViewPager 中的某些 fragment 上滑动

安卓 C++ : uncaught exception from loaded shared library