SilverBlue SilverBlue - 3 months ago 9
Android Question

How it works that XML show all on display?

How it works, that android show me all boxes on display, whatever I have a 4" Display or a 7" Display? It's okay, that android show the boxes a little bit smalles, but I must have all the boxes on display.

<?xml version="1.0" encoding="UTF-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:background="@drawable/box_ressourcen">


<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/box"
android:id="@+id/box1"
android:showDividers="beginning"
android:layout_gravity="top"
android:layout_alignParentStart="true"
android:layout_alignParentTop="false"
android:layout_below="@+id/imageView"
android:layout_marginTop="-20dp"
android:layout_alignParentEnd="false"
android:gravity="center">

<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/myimage1"
android:src="@drawable/inventar"/>

</LinearLayout>

<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:layout_alignParentStart="false"
android:src="@drawable/inventar_ressourcen"
android:layout_marginTop="-25dp" />

<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/box"
android:id="@+id/box2"
android:showDividers="beginning"
android:layout_gravity="top"
android:layout_alignTop="@+id/box1"
android:layout_toEndOf="@+id/box1"
android:gravity="center">

<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/imageView2"
android:src="@drawable/inventar" />
</LinearLayout>

<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/box"
android:id="@+id/box3"
android:showDividers="beginning"
android:layout_gravity="top"
android:layout_alignTop="@+id/box2"
android:layout_toEndOf="@+id/box2"
android:gravity="center">

<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/imageView3"
android:src="@drawable/inventar" />
</LinearLayout>

<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/box"
android:id="@+id/box4"
android:showDividers="beginning"
android:layout_gravity="top"
android:gravity="center"
android:layout_alignTop="@+id/box3"
android:layout_toEndOf="@+id/box3">

<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/imageView4"
android:src="@drawable/inventar" />
</LinearLayout>

</RelativeLayout>

Answer

It depends with the sizes of your Views.

Its up to you to decide that you are going to show everything in the screen size or you let it to scroll in the screen.

You can divide your screen using XML , code or using both.

If you want you can go for flexed sizes (width / height) or wrap it and when you wrap it ,it will take the height of its child/children or you can separate layouts with a ratio again using XML ,code or both.

read about weight_sum and layout_weight also how to give sizes to layouts based on the screen size

What is android:weightSum in android, and how does it work?

https://developer.android.com/training/multiscreen/screensizes.html

https://developer.android.com/guide/practices/screens_support.html

https://developer.android.com/training/multiscreen/screendensities.html

easiest one for you at this stage will be this http://stackoverflow.com/a/12302811/5188159

also read about how to set sizes based on screen size which will display your XML in the same way in any screen

simple math - allocate my layout height 10% from the screen so the size will keep the ratio in any kind of a screen

as a code snippet this will give you the screen size height and width for the latest visions of android

 DisplayMetrics displaymetrics = new DisplayMetrics();
     this.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
        int height = displaymetrics.heightPixels;
        int width = displaymetrics.widthPixels;

now you can set a size problematically using the ratios To learn it you can search ;) i'm not telling you that :) and good luck!

Comments