Dumped XML Layout File padding positions not behaving correctly

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?


Asked by: Cherry864 | Posted: 20-01-2022






Answer 1

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 by: Owen797 | Posted: 21-02-2022



Answer 2

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 by: Blake628 | Posted: 21-02-2022



Answer 3

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 by: Dainton161 | Posted: 21-02-2022



Similar questions

android - Google Maps & apps with mapview have different current positions

I have a mapview where I want to track the user's current location. GPS as well as 'use wireless networks' is activated in my phone settings. Nevertheless, since I'm indoor I don't get a GPS fix, therefore the location is determined via network; wifi spot is available. I have the Google Maps app running as well as my application running. Strangely, the current location differes between Google Maps and my ap...


How to handle the positions in Gallery android?

How to handle the positions in Gallery.I need to change the background of image at perticular position.Iam able to change the background image of selected image successfully within the onItemClick method.But i need to change the old selected background image also as non-selected one. public void onItemClick(AdapterView&lt;?&gt; arg0, View view, int position, long arg3) { //previouse selected image ...


android - File won't read into multiple array positions

I'm trying to store each line from a file into an arraylist and then combine two arraylists into one. Currently, when I try this, all the different lines are being stored in one line. I want it to say something like User : Score . However, right now it is showing up like UseruserUsernamePerson : Score. (many different names and only one score). Can anyone see where I'm going wrong here? Also, pardon my poor naming practi...


java - unable to get touched x and y positions back

I just started learning how to program for android and cant seem to get the x positions for when someone clicks on the screen to appear in log cat. (im using an emulator if that has to do with anything) when i do click on the screen nothing happens. Here is my program on startup i get no errors. also using a relative layout package com.practice; import android.app.Activity; import android.os.Bundle; import...


java - setting the exact x,y positions of buttons in a relative layout

I was wondering how i could set the exact x,y positions of a button in a relative layout. I want to try and not use an absolute layout. When i looked at similar posts most of them only showed how to align things exactly in the center or to the left of the screen, is there a way to align things at an exact position maybe by subtracting the distance from a margin by w/e dpi


java - Use Pixels to set positions and size in Android?

I know people asked how to support different sizes but they only cared about the dimensions of the images. My question is somehow different. I want to know if using pixels is a good way to scale everything and also to position images on the screen. Is there a better way? I am creating a 2D game BTW. Regards, Baracat


android - Relative layout simple positions

Ok I have a relative layout inside a linear one.Until now,the relative layout was perfect,however now a big problem appeared. A relative layout is based on the others item's position.For ex button2 is at the bottom of button1,and so on...and if button 1 disappears,button2 gets..."nuts". That's my problem, when a button disappears one of the 4 buttons gets...up. What I need is to position the buttons like t...


layout - How can I draw a Rectangle in Android, of a given size, that positions itself in the view to which it is added?

I understand how to draw I shape, I am extending the View class, and overriding the onDraw, where I create a new ShapeDrawbale (Rectangle), which I then draw to the canvas: Rect rect = new Rect(x, y, x + width, y + height); shapeDrawable.setBounds(rect); shapeDrawable.getPaint().set(paint); shapeDrawable.draw(canvas); I then want to ad...


how to exchange Tab positions in android

I used nested tabs in Android , my requirement is the selected tab must be in the middle.I tried to solve that but did not find any solution for that. Can anybody tell me the solution? The following code to arrange tabs in my Activity. for (int i = 0; i &lt; activitis.length; i++) { position = i; intent1 = new Intent().setClass(this, Tab_team.class); intent1.putExtra("tabact...


opengl es - android - opengles- how to render a dynamic list of objects and update positions for each frame

Im working on an application for android that is using canvas operations to do all the drawing at the moment but Im switching everything over to opengles to gain performance. My only problem is I have no idea how to draw to screen a dynamically changing scene in opengles. I have a few questions so I guess Ill list them. 1.) How do I dynamically add onscreen objects based on a constantly changing list using opengles...






Still can't find your answer? Check out these communities...



Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android



top