Search code examples
androidandroid-layoutandroid-linearlayoutandroid-relativelayout

RelativeLayout within 2 LinearLayout


Hi i have to develop one expandablelistview android app.here i wish to create relativelayout within another 2 linearlayout.Here i have to please help me.how can i do. Here i have to run the app means the firstlinear layout have 2 values separately and second linearlayout have separate 2 value like below format.

This is wish to need the format:

* Order info
  Payment_method:
         Payment_method
  Subtotal
         Subtotal
* CustomerInfo
  Firstname
        Firstname
  Lastname
        Lastname
  Phone
        Phone

but i got the below format. enter image description here Why above space is occurred here.please help me.how can i resolve this error.

This is my android layout code:

main.xml:

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

    >

    <ExpandableListView android:id="@+id/android:list" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent">
    </ExpandableListView>
    </LinearLayout>

group_row.xml:

   <?xml version="1.0" encoding="utf-8"?>
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:layout_marginTop="170px"
   >
   <TextView
    android:id="@+id/order" 
    android:text="Order"
    android:layout_width="wrap_content"
    android:layout_height="70px"
    android:layout_marginLeft="70px"
    android:gravity="center_vertical"
    android:textColor="#FFFFFFFF"
    android:textSize="20dip"
            android:textStyle="bold"
/>

   </LinearLayout>

Expandablelistview.xml:

<?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="match_parent"
>
<LinearLayout
android:id="@+id/linear_layout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
 android:id="@+id/payment_method1"
 android:paddingLeft="5px"
 android:textSize="15dip"
 android:text="payment_method"
 android:textStyle="bold"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"/> 
 <TextView
 android:id="@+id/payment_method"
 android:paddingLeft="75px"
 android:textSize="15dip"
 android:textColor="#10bcc9"
 android:textStyle="bold"
 android:text="payment_method"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"/>
 <TextView
 android:id="@+id/subtotal1"
  android:text="subtotal"
 android:paddingLeft="5px"
 android:textSize="15dip"

 android:textStyle="bold"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"/>
<TextView
android:id="@+id/subtotal"
  android:text="subtotal"
 android:paddingLeft="65px"
 android:textSize="15dip"
android:textColor="#10bcc9"
android:textStyle="bold"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"/>
</LinearLayout>
   <LinearLayout
 android:id="@+id/linear_layout2"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:layout_below="@id/linear_layout1"
 android:orientation="vertical" >
  >
              <TextView
 android:id="@+id/firstname1"
 android:paddingLeft="5px"
 android:textSize="15dip"

android:textStyle="bold"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"/> 
               <TextView
android:id="@+id/firstname"
 android:paddingLeft="65px"
 android:textSize="15dip"
android:textColor="#10bcc9"
android:textStyle="bold"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"/>

              <TextView
android:id="@+id/lastname1"

 android:paddingLeft="5px"
 android:textSize="15dip"

android:textStyle="bold"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"/>
              <TextView
android:id="@+id/lastname"

 android:paddingLeft="65px"
 android:textSize="15dip"
android:textColor="#10bcc9"
android:textStyle="bold"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"/>
<TextView
android:id="@+id/phone1"
 android:paddingLeft="5px"
 android:textSize="15dip"

android:textStyle="bold"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"/> 
  <TextView
android:id="@+id/phone"
 android:paddingLeft="65px"
 android:textSize="15dip"
android:textColor="#10bcc9"
android:textStyle="bold"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"/>
  </LinearLayout>


   </RelativeLayout>

please refer my layout file and give me solution for this.


Solution

  • Your layout did not include any code that would display the down arrow followed by the string "Order Info" or the down arrow followed by the string "Customer Info". I assume that is intentional.

    It seems that you started this with a linear layout and changed it to a relative layout. Here is what I would do: 1 - Remove android:orientation="vertical" from relative layout. 2 - Add id to both the linear layouts 3 - Add code to place second linear layout below first to second linear layout. android:layout_below="@id/linear_layout1"

    Here is the complete layout:

    <?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="match_parent" >
    
    <LinearLayout
        android:id="@+id/linear_layout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
    
        <TextView
            android:id="@+id/payment_method1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="5dp"
            android:text="payment_method"
            android:textSize="15dip"
            android:textStyle="bold" />
    
        <TextView
            android:id="@+id/payment_method"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="75dp"
            android:text="payment_method"
            android:textColor="#10bcc9"
            android:textSize="15dip"
            android:textStyle="bold" />
    
        <TextView
            android:id="@+id/subtotal1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="5dp"
            android:text="subtotal"
            android:textSize="15dip"
            android:textStyle="bold" />
    
        <TextView
            android:id="@+id/subtotal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="65dp"
            android:text="subtotal"
            android:textColor="#10bcc9"
            android:textSize="15dip"
            android:textStyle="bold" />
    </LinearLayout>
    
    
    <LinearLayout
        android:id="@+id/linear_layout2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/linear_layout1"
        android:orientation="vertical" >
    
        <TextView
            android:id="@+id/firstname1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="5dp"
            android:text="First Name"
            android:textSize="15dip"
            android:textStyle="bold" />
    
        <TextView
            android:id="@+id/firstname"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="65dp"
            android:text="first_name"
            android:textColor="#10bcc9"
            android:textSize="15dip"
            android:textStyle="bold" />
    
        <TextView
            android:id="@+id/lastname1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="5dp"
            android:text="Last Name"
            android:textSize="15dip"
            android:textStyle="bold" />
    
        <TextView
            android:id="@+id/lastname"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="65dp"
            android:text="last_name"
            android:textColor="#10bcc9"
            android:textSize="15dip"
            android:textStyle="bold" />
    
        <TextView
            android:id="@+id/phone1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="5dp"
            android:text="Phone"
            android:textSize="15dip"
            android:textStyle="bold" />
    
        <TextView
            android:id="@+id/phone"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="65dp"
            android:text="phone"
            android:textColor="#10bcc9"
            android:textSize="15dip"
            android:textStyle="bold" />
    </LinearLayout>