0

I am really struggling with my xml layout, even though I have over a year of experience working on android :). Anyway I need to create an xml layout as following:

enter image description here

I tried with this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="100">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dp" 
    android:layout_weight="5">
</RelativeLayout>
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dp" 
    android:layout_weight="15">
</RelativeLayout>
 <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dp" 
    android:layout_weight="5" >
</RelativeLayout>
 <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dp" 
    android:layout_weight="20" >
</RelativeLayout>
 <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dp" 
    android:layout_weight="5" >
</RelativeLayout>
 <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dp" 
    android:layout_weight="50" >
</RelativeLayout>

</LinearLayout>

enter image description here

And everything looks alright till moment i want to add child to some inner layout. So when i add listView to RelativeLayout, marked with number 3, it doesn't match it's parent but takes whole screen. How can i add listview to inner layouts 2 and 3 so they match their boundaries?

Dave Hogan
  • 3,201
  • 6
  • 29
  • 54
prowebphoneapp
  • 87
  • 1
  • 11
  • 1
    maybe set the `layout_height` for all layouts to `wrap_content`? – Boris Strandjev Jul 07 '13 at 08:44
  • i tried with match_parent and wrap_content but in both case listView (or imageView, if i add it to layout 1) occupies whole screen. – prowebphoneapp Jul 07 '13 at 08:48
  • Dude try doing it top-to-bootom. Your approach is correct, see if the IMAGE you used has dimensions in range of what you want. – Kunal S. Kushwah Jul 07 '13 at 08:53
  • I think the problem is that the content you add in the `RelativeLayouts` do not have the restriction `wrap_content`? Be ware it makes no sense to have `match_parent` inside a view that declares `wrap_content` – Boris Strandjev Jul 07 '13 at 08:53
  • I really dont know but you should separate your layout into two parts one with part that contains all element above listview and one with layout that contain listview. – kaushal trivedi Jul 07 '13 at 08:53
  • Kaushaii have two listViews(2,3) and one part for ImageView and TextView. Boris i set match_parent for views i am adding to 1,2,3 but somehow they match root parent. – prowebphoneapp Jul 07 '13 at 08:59

1 Answers1

2

Look at this demo code,may be you can do some changes in this and apply it for your use. directly put this code in your xml.

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.2" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/com_facebook_button_grey_focused" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.3" 
        android:layout_margin="10dp"
        >

        <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </ListView>
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" 
        android:layout_margin="10dp"
        >

        <ListView
            android:id="@+id/listView2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </ListView>
    </RelativeLayout>

</LinearLayout>
kaushal trivedi
  • 3,405
  • 3
  • 29
  • 47