Search code examples
androidandroid-layoutandroid-linearlayoutandroid-relativelayout

Android layout customize


I'm beginning in Android development and I have still some issues with layout.

This is the render I want : render
(source: hostingpics.net)

I did this but I really don't understand how i can do this type of layout.

This is my xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:minWidth="25px"
    android:minHeight="25px">
    <LinearLayout
        android:orientation="horizontal"
        android:minWidth="25px"
        android:minHeight="25px"
        android:layout_width="fill_parent"
        android:layout_height="90px"
        android:id="@+id/linearLayout1">
        <ImageView
            android:src="@android:drawable/ic_menu_gallery"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/imageView1" />
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:minWidth="25px"
        android:minHeight="25px"
        android:layout_width="fill_parent"
        android:layout_height="90px"
        android:id="@+id/linearLayout2">
        <TextView
            android:text="Bonus1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/textView1"
            android:layout_gravity="center" />
        <TextView
            android:text="Bonus2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/textView2"
            android:layout_gravity="center" />
    </LinearLayout>
</LinearLayout>

Solution

  • Use linear Layouts


    XML-CODE::

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="2" >
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#FFFFFF"
            android:orientation="horizontal"
            android:padding="5dp"
            android:weightSum="2" >
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#FFFFFF"
                android:padding="10dp" >
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_margin="5dp"
                    android:layout_weight="1"
                    android:background="#000000"
                    android:padding="5dp" >
    
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="#FFFFFF"
                        android:gravity="bottom|center" >
    
                        <TextView
                            android:id="@+id/textView3"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginBottom="2dp"
                            android:layout_marginLeft="5dp"
                            android:layout_marginRight="5dp"
                            android:text="TextView"
                            android:textStyle="bold" />
                    </LinearLayout>
                </LinearLayout>
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="5dp"
                    android:layout_weight="1" >
    
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="#FFFFFF"
                        android:orientation="vertical"
                        android:weightSum="2" >
    
                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:background="#FFFFFF"
                            android:orientation="vertical" >
    
                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:layout_margin="5dp"
                                android:layout_weight="1"
                                android:background="#000000"
                                android:padding="5dp" >
    
                                <LinearLayout
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:background="#FFFFFF"
                                    android:gravity="bottom|center" >
    
                                    <TextView
                                        android:id="@+id/textView2"
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:layout_marginBottom="2dp"
                                        android:layout_marginLeft="5dp"
                                        android:layout_marginRight="5dp"
                                        android:text="TextView"
                                        android:textStyle="bold" />
                                </LinearLayout>
                            </LinearLayout>
    
                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:layout_margin="5dp"
                                android:layout_weight="1"
                                android:background="#000000"
                                android:padding="5dp" >
    
                                <LinearLayout
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:background="#FFFFFF"
                                    android:gravity="bottom|center" >
    
                                    <TextView
                                        android:id="@+id/textView1"
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:layout_marginBottom="2dp"
                                        android:layout_marginLeft="5dp"
                                        android:layout_marginRight="5dp"
                                        android:text="TextView"
                                        android:textStyle="bold" />
                                </LinearLayout>
                            </LinearLayout>
                        </LinearLayout>
                    </LinearLayout>
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#FFFFFF"
            android:gravity="bottom|center" >
        </LinearLayout>
    
    </LinearLayout>
    

    Snapshot

    enter image description here


    Note:: Use this code and customize the way you wish

    Hope this helps !!