0

I would like to create an app that divides the screen into two squarish halves; in either orientation. The content within each half should rotate; but the two areas should remain fixed.

layout diagram

Could you tell me how to achieve this layout? I would like to place an embedded browser in one half, and a QR code scanner in the other.

I imagine this is a noobish question; I've done very little android development.

HardlyNoticeable
  • 497
  • 9
  • 26
  • this may help you http://stackoverflow.com/questions/2698817/linear-layout-and-weight-in-android – H Raval Mar 19 '16 at 07:00
  • 1
    you have to create two different layouts to achieve this,when the screen rotates the layout will change according to your requirement ..see link: http://stackoverflow.com/questions/9630952/xml-layout-changes-while-changing-orientation – Narendra Baratam Mar 19 '16 at 07:06
  • did you use layout weight sum for this. – Bhunnu Baba Mar 19 '16 at 07:30
  • @NarendraBaratam and Mohamad: Thanks guys; a combination of your solutions worked for me. I needed two layouts; Mohamad's Vertical and Horizontal layouts. With the Horizontal layout in a layout-land folder. – HardlyNoticeable Mar 19 '16 at 08:44

2 Answers2

0

set layout_weight to 1 in both LinearLayout will divide the screen equally.

<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"
tools:context=".Main"
android:baselineAligned="false"
android:orientation="horizontal">

<LinearLayout
    android:layout_weight="1"
    android:background="#9561A7"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!--views of the first section-->
        />

</LinearLayout>
<LinearLayout
    android:layout_weight="1"
    android:background="#006C91" 
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!--views of the second section-->
      />
</LinearLayout>

good luck .

0

you can use layout weight sum and layout weight for this purpose.

use to following line of code:

      <LinearLayout
                android:id="@+id/head"
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:orientation="horizontal"
                android:weightSum="2"
                android:baselineAligned="false"
                android:layout_gravity="center_horizontal">

                <LinearLayout
                    android:layout_width="50dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"> 

                <LinearLayout
                    android:layout_width="50dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"> 

       </LinearLayout>
Bhunnu Baba
  • 1,742
  • 15
  • 22