tags:

views:

23

answers:

2
+1  Q: 

Dynamic view high

Hi there, i'm new on Android plattform. I'm trying make a View that divide the screen in three sections. The first section should be 200dip high, the third section should be 50 dip high and the middle section should take the remaining place in the middle. Is there any way to implement it? I tried some ways but either it doesn't work or the app crashed. Thanks for help Patrik

+1  A: 

Sure. Use a RelativeLayout which looks like this.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <!-- Defining the top view -->
  <View android:layout_alignParentTop="true"
    android:layout_height="200dip"
    android:layout_width="fill_parent"
    android:id="@+id/top_view"
    android:background="#FFFF00"/>
  <!-- Defining the bottom view -->
  <View android:layout_alignParentBottom="true"
    android:layout_height="50dip"
    android:layout_width="fill_parent"
    android:id="@+id/bottom_view"
    android:background="#00FFFF"/>
  <!-- Defining the view in between those views -->
  <View android:layout_above="@id/bottom_view"
    android:layout_below="@id/top_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FF0000"/>
</RelativeLayout>

Provided comments in the code for you.

Octavian Damiean
I like this proposal even better than mine. +1
Ralkie
A: 

I usually achieve this by setting layout_height/width of fixed Views to specific values (e.g. android:layout_height="200dp") and setting android:layout_weight="1" with android:layout_height="wrap_content" for dynamic View. In that case LinearLayout may be used as containing ViewGroup.

Ralkie