Android Nested Linear Layous inside Relative Layout

  • Replies:3
  • OpenNot stickiedUnanswered
  • Forum posts: 4

Nov 9, 2015 11:04:04 AM via Website

Guys

I have on this all weekend and its driving me crazy

I am designing a custom Listview the code of my view is as follows

<RelativeLayout xmlns:android="XXXXX"
xmlns:tools=XXXXXX"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".nestedLayoutActivity" >
<LinearLayout
android:id="@+id/ll1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:eek:rientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:eek:rientation="vertical" >
<TextView
android:id="@+id/Sr2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Medium Text"
android:textColor="#000"
android:textSize="8dp" />
<TextView
android:id="@+id/Sr3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Sr2"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/imageView1"
android:text="Medium Text"
android:textColor="#000"
android:textSize="8dp" />
<TextView
android:id="@+id/Sr4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Sr3"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/imageView1"
android:text="Medium Text"
android:textColor="#000"
android:textSize="8dp" />
<TextView
android:id="@+id/Sr5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Sr4"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/imageView1"
android:text="Medium Text"
android:textColor="#000"
android:textSize="8dp" />
<TextView
android:id="@+id/Sr6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Sr5"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/imageView1"
android:text="Medium Text"
android:textColor="#000"
android:textSize="8dp" />
<TextView
android:id="@+id/Sr7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Sr6"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/imageView1"
android:text="Medium Text"
android:textColor="#000"
android:textSize="8dp" />
<TextView
android:id="@+id/Sr8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Sr7"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/imageView1"
android:text="Medium Text"
android:textColor="#000"
android:textSize="8dp" />
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/Sr2"
android:layout_alignTop="@+id/imageView1"
android:layout_marginLeft="10dp"
android:text="Medium Text"
android:textColor="#000"
android:textSize="8dp" />
</LinearLayout>
</RelativeLayout>

I am trying to get two linear layouts inside a relative layout to be side by side with layout on left taking 30% of width and layout on right taking 70%

The reason I need two layouts inside is that the layout on the left will contain an imageview which will grow bigger or smaller depending on device used while keeping proportion of 30% and the layout on right had 7 textviews each one under anther giving details.

The code above sort of does it but both views are on top of each other

Any idea where I am going wrong

Any help appreciated

Mark

  • Forum posts: 207

Nov 9, 2015 12:19:14 PM via Website

try this

xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".nestedLayoutActivity" >
android:id="@+id/ll1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />

android:id="@+id/ll2"
android:layout_width="match_parent"
android:layout_below="@+id/ll1"
android:layout_height="wrap_content"
android:orientation="vertical" >
android:id="@+id/Sr2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Medium Text"
android:textColor="#000"
android:textSize="8dp" />
android:id="@+id/Sr3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Sr2"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/imageView1"
android:text="Medium Text"
android:textColor="#000"
android:textSize="8dp" />
android:id="@+id/Sr4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Sr3"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/imageView1"
android:text="Medium Text"
android:textColor="#000"
android:textSize="8dp" />
android:id="@+id/Sr5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Sr4"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/imageView1"
android:text="Medium Text"
android:textColor="#000"
android:textSize="8dp" />
android:id="@+id/Sr6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Sr5"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/imageView1"
android:text="Medium Text"
android:textColor="#000"
android:textSize="8dp" />
android:id="@+id/Sr7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Sr6"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/imageView1"
android:text="Medium Text"
android:textColor="#000"
android:textSize="8dp" />
android:id="@+id/Sr8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Sr7"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/imageView1"
android:text="Medium Text"
android:textColor="#000"
android:textSize="8dp" />
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/Sr2"
android:layout_alignTop="@+id/imageView1"
android:layout_marginLeft="10dp"
android:text="Medium Text"
android:textColor="#000"
android:textSize="8dp" />

  • Forum posts: 4

Nov 9, 2015 1:07:36 PM via Website

Sorry Ashish it does exactly the same

the only difference in your code and mine is one wrap_contents in the first linear layout

They are both on top of each other how do I get a 30/70 split p[lease

Mark#

  • Forum posts: 207

Nov 9, 2015 1:16:08 PM via Website

try this
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".nestedLayoutActivity" >

<TableRow 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:weightSum="1">

android:id="@+id/ll1"
android:layout_width="0dp"
android:layout_weight=".3"
android:layout_height="wrap_content"
android:orientation="vertical" >
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />

android:id="@+id/ll2"
android:layout_width="0dp"
android:layout_weight=".7"
android:layout_height="wrap_content"
android:orientation="vertical" >
android:id="@+id/Sr2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Medium Text"
android:textColor="#000"
android:textSize="8dp" />
android:id="@+id/Sr3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Sr2"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/imageView1"
android:text="Medium Text"
android:textColor="#000"
android:textSize="8dp" />
android:id="@+id/Sr4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Sr3"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/imageView1"
android:text="Medium Text"
android:textColor="#000"
android:textSize="8dp" />
android:id="@+id/Sr5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Sr4"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/imageView1"
android:text="Medium Text"
android:textColor="#000"
android:textSize="8dp" />
android:id="@+id/Sr6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Sr5"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/imageView1"
android:text="Medium Text"
android:textColor="#000"
android:textSize="8dp" />
android:id="@+id/Sr7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Sr6"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/imageView1"
android:text="Medium Text"
android:textColor="#000"
android:textSize="8dp" />
android:id="@+id/Sr8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Sr7"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/imageView1"
android:text="Medium Text"
android:textColor="#000"
android:textSize="8dp" />
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/Sr2"
android:layout_alignTop="@+id/imageView1"
android:layout_marginLeft="10dp"
android:text="Medium Text"
android:textColor="#000"
android:textSize="8dp" />