1

On android phone under settings -> developer options you have an option to "Show layout bounds". If you check this, you get to see every edge of every view element on your android phones default GUI. These are shown on a few applications also, like Instagram and Facebook. What i want to do is to understand the algorithm that my phone uses to detect these edges.

An example (with "Show layout bounds" - option checked):

enter image description here

edit: I want to get the layout bonds without activating the developer option. Suppose that the layout is unknown and i want to get it using a similar algorithm that my phone already uses.

edit 2: Activating "Show layout bounds" programmaticly requires the app to be a system app, which is not an option. Activating it manually and then run the program is not an option either. This is because i not only want to use the layout bonds, i also want understand the algorithm behind it.

Taegos
  • 343
  • 3
  • 6
  • 15

2 Answers2

0

This is a long shot, but you could also simply calculate it by taking a device's width, and subtract it with the values you known such as the marginLeft of the thumbnail, the width of that thumbnail, the marginRight of the following button, and the width of that button (or the group where you have the check box and the arrow for people you already follow?)...

To find the width of your device, you can use this:

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;

taken from here > Get screen dimensions in pixels

Community
  • 1
  • 1
sdieters
  • 175
  • 13
  • I might have been unclear, it is the "red lines" that i want to get. Suppose that the red lines are unknown and i want to get them? **How does the android device get them when you enable the option for it in the developer tools? I want to replicate this**. Activating that option programmaticly requires the app to be a system app, which is not an option. Activating it manually and then run the program is not an option either. – Taegos May 24 '16 at 18:54
0

To create such border, use this code as a drawable resource, and put it as a background for your layout's or layout groups:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <!-- view background color -->
    <solid
        android:color="#00000000" >
    </solid>

    <!-- view border color and width -->
    <stroke
        android:width="1dp"
        android:color="#282828" >
    </stroke>

    <!-- The radius makes the corners rounded -->
    <corners
        android:radius="5dp"   >
    </corners>

</shape>

You can change the color to whatever you want, and if you dont want to have round corners, just set the radius to 1 (not sure if 0 will work, or if you can completely remove the corners bit). Also keep in mind that this will ONLY give you the red lines, not the blue corners. I havent figured out how to do those yet.

sdieters
  • 175
  • 13
  • Thank you, but it is not what i am looking for. I know how to draw the shapes, **What i want to do** is to replicate the algorithm that my phone uses to detect these edges. How can the phone know where the borders/margins are on apps like Instagram/Facebook? – Taegos May 24 '16 at 23:42