Dumped XML Layout File padding positions not behaving correctly

1

I've been trying to figure out how to make some sense of a dumped XML layout, and it's progressing 'pretty good'. The only thing I'm currently unsure about is the following:

When I use the command:

aapt dump xmltree <pathofapk> <pathofxmlfile>

I get the following result:

   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

That's all good, but what I'm trying to figure out is how to convert the following code into the XML layout file:

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

Converting those values to decimal would result in:

paddingLeft:2561
paddingTop:1025

All good, but I've been trying to figure out what the (type 0x5 means). With all other types, the result is defined in the Android.util.TypedValue.class file

Decompiling that, gives the following result for 0x5:

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

Makes sense, in a way. But, I need to know what kind of value it is, so looking down, I find the following value:

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

But, when I try to use 2561mm and 1025mm (It's a tad much anyway, 25cm is.. larger than my screen), The whole screen is filled with the 'parent LinearLayout'.

I have no clue what's wrong. Can anyone enlighten me on this subject?

android
asked on Stack Overflow Dec 30, 2009 by Mats Willemsen • edited Jul 25, 2017 by Vadim Kotov

3 Answers

3

The data structure for these typed values is defined here:

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

Inside is an enum of the type codes; after that are definitions of the bits for fraction and unit types. (What you are seeing here are unit types -- i.e., 20sp.)

answered on Stack Overflow Dec 30, 2009 by hackbod • edited Jul 25, 2017 by Vadim Kotov
1

And yes, you were right! I was messing around a bit right before this answer, and I found out the same thing.

I was always thinking about some float value, because it'd make a lot more sense, but I couldn't make anything of the value 0xa01 in float, so after a bit of snooping around, I found the following function:

public static float complexToFloat (int complex)

When I call this method with the complex variable set as 0xa01, I get the proper result, which is 10.0 (And, 4.0 for the other value).

So yeah, 10.0mm / 4.0mm did the trick!, Thanks a bunch ^_^

answered on Stack Overflow Dec 30, 2009 by Mats Willemsen
0

If I had to guess, you are misinterpreting the values. 1025 and 2561 may be the decimal equivalents of those hex values, but there are no units of measure in Android where those would make sense -- those numbers are too big even for px, let alone mm. My guess is that they are encoded differently than you are expecting. For example, I suspect they're really floating-point values, since those are legal for dimensions.

You could test this theory by creating a scrap project, setting a handful of padding values in a layout, compiling it, then running your dump on your own APK, to see if you can reverse engineer what's happening. Or, you could try to look at the code to aapt itself, which should be in the open source tree.

answered on Stack Overflow Dec 30, 2009 by CommonsWare

User contributions licensed under CC BY-SA 3.0