Frage

I am inflating a layout in a Linear Layout.But at run time it is not showing up the proper layout .data is getting mixed up with each other.No proper spacing between the data. this is how it is looking up Image How it is coming up

This is my Activity Code

void setApprovalDetailsData(){
        resultTrips = (LinearLayout)findViewById(R.id.trip_list);
        LinearLayout.LayoutParams mainTripDetailsLayout = new LinearLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        LayoutInflater inflater = (LayoutInflater) getBaseContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        LinearLayout.LayoutParams forUnderLine = new LinearLayout.LayoutParams(
                LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
        forUnderLine.setMargins(0, 0, 0, 0);
        //mainTripDetailsLayout.setMargins(0, 40, 0, 0);

        for (int i = 0; i < 13; i++) {
            TextView line = new TextView(this);
            line.setBackgroundResource(R.layout.shape_line);
            line.setLayoutParams(forUnderLine);
            if (i != 0) {
                resultTrips.addView(line);
            }

            LinearLayout tripdetailsdata = (LinearLayout) inflater.inflate(
                    R.layout.tripdetailsdata, null);
            resultTrips.addView(tripdetailsdata);
        }
        TextView dummy = new TextView(this);
        dummy.setLayoutParams(mainTripDetailsLayout);
        resultTrips.addView(dummy);
    }

Main XML file

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <LinearLayout
        android:id="@+id/mainLinearLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:background="@drawable/top_bg"
        android:orientation="horizontal" >
        <ImageView 
            android:id="@+id/back_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/back_btn"
            android:onClick="goBack"
            android:layout_marginTop="5dp"
            android:layout_marginLeft="10dp"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="50dp"
            android:text="Self Travel Request Queues"
            android:textColor="@android:color/white" />
    </LinearLayout>



    <LinearLayout
        android:layout_width="fill_parent"
        android:id="@+id/headerList"
        android:layout_below="@+id/mainLinearLayout"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

    <LinearLayout
       android:id="@+id/options"
           android:layout_width="fill_parent"
           android:layout_height="39dp"
           android:background="@drawable/gray_bg123"
           android:orientation="horizontal"
           android:weightSum="5">

        <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="RequestedOn"
            android:layout_marginTop="5dp"
            android:layout_marginLeft="2dp"
            android:layout_weight="1"/>
        <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="ApprovalID"
            android:layout_marginTop="5dp"
            android:layout_weight="1"/>
        <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
             android:text="TripDate"
            android:layout_marginTop="5dp"
            android:layout_weight="1"/>
        <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
             android:text="TripID"
            android:layout_marginTop="5dp"
            android:layout_weight="1"/>
        <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
             android:text="ApprovalStatus"
            android:layout_marginTop="5dp"
            android:layout_weight="1"/>

        <TextView
            android:layout_width="6dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:text="hello"
            android:layout_weight="1"
            android:visibility="invisible" />

    </LinearLayout>


    </LinearLayout>
    <ScrollView 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_below="@+id/headerList">

        <LinearLayout 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:id="@+id/trip_list"
            android:orientation="vertical">
        </LinearLayout>

    </ScrollView>
    <LinearLayout
        android:id="@+id/footerLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal"
        android:background="@drawable/top_bg" >


    </LinearLayout>
</RelativeLayout>

TripDetails XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainResultLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:baselineAligned="false"
    android:gravity="center"
    android:orientation="horizontal" >

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/request_date"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:layout_weight="1"
            android:text="25 Sep 2013 | 09:45" />

        <TextView
            android:id="@+id/approval_id"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:layout_weight="1"
            android:text="In30075042" />

        <TextView
            android:id="@+id/trip_date"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:layout_weight="1"
            android:text="25 Sep 2013" />

        <TextView
            android:id="@+id/trip_id"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:layout_weight="1"
            android:text="FB30073KIFWB" />

        <TextView
            android:id="@+id/approval_status"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:layout_weight="1"
            android:text="Waiting" />
    </LinearLayout>

</LinearLayout>

The image link i have posted that is not showing data in proper way.Please help me to make it proper.Thanks

After @gaurav suggestion this is how it is showing up Still not proper

Image After Gaurav Suggestion

War es hilfreich?

Lösung

Try this tripdetailsdata.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainResultLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:baselineAligned="false"
    android:gravity="center"
    android:orientation="horizontal" >

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="5" >

        <TextView
            android:id="@+id/request_date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="25 Sep 2013 | 09:45" />

        <TextView
            android:id="@+id/approval_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="In30075042" />

        <TextView
            android:id="@+id/trip_date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="25 Sep 2013" />

        <TextView
            android:id="@+id/trip_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="FB30073KIFWB" />

        <TextView
            android:id="@+id/approval_status"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Waiting" />
    </LinearLayout>

</LinearLayout>

And in your activity xml

<LinearLayout
       android:id="@+id/options"
           android:layout_width="fill_parent"
           android:layout_height="39dp"
           android:background="@drawable/gray_bg123"
           android:orientation="horizontal"
           android:weightSum="5">

Andere Tipps

What you are trying to do is to display a data table. Therefore I think you should use a TableLayout instead of a LinearLayout:

https://developer.android.com/reference/android/widget/TableLayout.html

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top