Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BorderLayout in android?

Is there a way to implement a working reusable border layout in android ? One that behaves just like swing's BorderLayout: Maximizing the middle and reducing the rest to minimal size ?

like image 360
Joel Avatar asked Jul 22 '26 07:07

Joel


2 Answers

Try out this and you will get the same behaviour as Swings BorderLayout (the result is shown in the picture):

BorderLayout Demo

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

<TextView
    android:id="@+id/north"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:background="@android:color/holo_orange_light"
    android:gravity="center_horizontal"
    android:text="North"
    android:textAppearance="@android:style/TextAppearance.Large" />

<TextView
    android:id="@+id/south"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="@android:color/holo_blue_light"
    android:gravity="center_horizontal"
    android:text="South"
    android:textAppearance="@android:style/TextAppearance.Large" />

<TextView
    android:id="@+id/west"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_above="@id/south"
    android:layout_alignParentLeft="true"
    android:layout_below="@id/north"
    android:background="@android:color/holo_red_light"
    android:gravity="center_vertical"
    android:text="West"
    android:textAppearance="@android:style/TextAppearance.Large" />

<TextView
    android:id="@+id/east"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_above="@id/south"
    android:layout_alignParentRight="true"
    android:layout_below="@id/north"
    android:background="@android:color/holo_purple"
    android:gravity="center_vertical"
    android:text="East"
    android:textAppearance="@android:style/TextAppearance.Large" />

<TextView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@id/south"
    android:layout_below="@id/north"
    android:layout_toLeftOf="@id/east"
    android:layout_toRightOf="@id/west"
    android:background="@android:color/holo_green_light"
    android:gravity="center"
    android:text="Center"
    android:textAppearance="@android:style/TextAppearance.Large" />

like image 130
Andy Avatar answered Jul 23 '26 22:07

Andy


You can use a RelativeLayout together with android:layout_weight attributes to get the same effect.

like image 29
Ted Hopp Avatar answered Jul 23 '26 23:07

Ted Hopp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!