0

I have this layout. Now i want to use two layout with same details and these two layouts will be inside this layout so that i can show the same layout side by side in a layout Here is my xml file please help me on this :

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:baselineAligned="false" 
    android:gravity="center">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical" 
        android:gravity="center">
        <ImageView
            android:id="@+id/flightLogo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/spicejet" />
        <TextView
            android:id="@+id/flightCompany"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:textSize="12sp"
            android:text="SpiceJet"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/flightNumber"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:textSize="10sp"
            android:text="SG-142" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical" 
        android:gravity="center">
        <TextView
            android:id="@+id/departLocation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="BOS"
            android:gravity="center"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/departTime"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="17:40" />

        <TextView
            android:id="@+id/departDate"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Jan 19" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical" 
        android:gravity="center">

        <TextView
            android:id="@+id/arrivalLocation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="SOF"
            android:gravity="center"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/arrivalTime"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="23:45" />

        <TextView
            android:id="@+id/arrivalDate"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Jan 19" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical" 
        android:gravity="center">

        <TextView
            android:id="@+id/duration"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="6h45m"
            android:gravity="center"
            android:textStyle="bold" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical"
        android:gravity="center" >

        <TextView
            android:id="@+id/totalCost"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="30,193"
            android:textColor="#0000FF"
            android:gravity="center"
            android:textStyle="bold" />

        <ImageView
            android:id="@+id/bookButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:src="@drawable/book" />
    </LinearLayout>  

</LinearLayout>
Developer
  • 6,292
  • 19
  • 55
  • 115

1 Answers1

2

both widths for the sub layouts are match_parent so only one will show, match_parent is for the main layout and all sublayouts and elements should have fill_parent instead, Also because you are using weight you can set the width to 0dp and the weight will take care of the scaling

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:baselineAligned="false" 
    android:gravity="center">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical" 
        android:gravity="center">
        <ImageView
            android:id="@+id/flightLogo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/spicejet" />
        <TextView
            android:id="@+id/flightCompany"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:textSize="12sp"
            android:text="SpiceJet"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/flightNumber"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:textSize="10sp"
            android:text="SG-142" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical" 
        android:gravity="center">
        <TextView
            android:id="@+id/departLocation"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="BOS"
            android:gravity="center"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/departTime"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="17:40" />

        <TextView
            android:id="@+id/departDate"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Jan 19" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical" 
        android:gravity="center">

        <TextView
            android:id="@+id/arrivalLocation"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="SOF"
            android:gravity="center"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/arrivalTime"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="23:45" />

        <TextView
            android:id="@+id/arrivalDate"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Jan 19" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical" 
        android:gravity="center">

        <TextView
            android:id="@+id/duration"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="6h45m"
            android:gravity="center"
            android:textStyle="bold" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical"
        android:gravity="center" >

        <TextView
            android:id="@+id/totalCost"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="30,193"
            android:textColor="#0000FF"
            android:gravity="center"
            android:textStyle="bold" />

        <ImageView
            android:id="@+id/bookButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:src="@drawable/book" />
    </LinearLayout>  

</LinearLayout>
Cob50nm
  • 911
  • 2
  • 9
  • 27
  • no i want this complete layout inside a main layout twice side bu side – Developer Aug 02 '13 at 09:54
  • but in my device it is not fiting up properly i am using micromax canvas – Developer Aug 02 '13 at 10:13
  • Beyond what I've shown, there's not much you can do about the scaling as the width will vary from device to device. Your only option would be doing something like http://stackoverflow.com/questions/9877946/text-size-and-different-android-screen-sizes – Cob50nm Aug 02 '13 at 10:28
  • I just kinda picked it up as I went along, and using the graphical layout thing in eclipse to drag stuff around then looking at the xml that it generates is good too, though it only really works for relative layouts – Cob50nm Aug 02 '13 at 11:29
  • i have to design many layout i am confused how could i do them .Designing for me is complicated .what could i do get away from it.i have just started work in android – Developer Aug 02 '13 at 11:49