-3

I have use two scroll views for two different layout. And those two layouts are inside a Linear Layout.

Here is my XML file. I don't why ScrollView is not working for me

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

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

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:orientation="horizontal" >

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:orientation="vertical" >

                        <ImageView
                            android:id="@+id/onewayflightLogo"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="3dp"
                            android:src="@drawable/spicejet" />

                        <TextView
                            android:id="@+id/onewayflightName"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="SpiceJet" />

                        <TextView
                            android:id="@+id/onewayflightNumber"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="9W - 496" />
                    </LinearLayout>

                    <LinearLayout
                        android:layout_marginTop="8dp"
                        android:layout_width="fill_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical" >

                        <TextView
                            android:id="@+id/onewayflightTime"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="5dp"
                            android:minLines="1"
                            android:text="06:00 - 7:05"
                            android:textSize="12dp" />

                        <TextView
                            android:id="@+id/onewayflightDuration"
                            android:layout_width="fill_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="5dp"
                            android:minLines="1"
                            android:text="1h 35m | Non Stop"
                            android:textSize="10dp" />
                        <TextView
                            android:id="@+id/onewayflightAmount"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="5dp"
                            android:minLines="1"
                            android:text="Rs 200000"
                            android:textSize="12dp" />
                    </LinearLayout>
                </LinearLayout>
                <View
                    android:layout_width="1dp"
                    android:layout_height="60dp"
                    android:background="@android:color/darker_gray" />
               <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:orientation="horizontal" >

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:orientation="vertical" >

                        <ImageView
                            android:id="@+id/retrunflightLogo"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="3dp"
                            android:src="@drawable/spicejet" />

                        <TextView
                            android:id="@+id/retrunflightName"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="SpiceJet" />

                        <TextView
                            android:id="@+id/retrunflightNumber"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="9W - 496" />
                    </LinearLayout>

                    <LinearLayout
                        android:layout_marginTop="8dp"
                        android:layout_width="fill_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical" >

                        <TextView
                            android:id="@+id/retrunflightTime"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="5dp"
                            android:minLines="1"
                            android:text="06:00 - 7:05"
                            android:textSize="12dp" />

                        <TextView
                            android:id="@+id/retrunflightDuration"
                            android:layout_width="fill_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="5dp"
                            android:minLines="1"
                            android:text="1h 35m |Non Stop"
                            android:textSize="10dp" />

                        <TextView
                            android:id="@+id/retrunflightAmount"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="5dp"
                            android:minLines="1"
                            android:text="Rs 200000"
                            android:textSize="12dp" />
                    </LinearLayout>
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>
</LinearLayout>

This is my main layout in which I am inflating my above xml dynamically through a loop

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

And in my activity code I am doing this:

void setTestResultData(){

    flightResult=(LinearLayout)findViewById(R.id.flightResultData);
    LinearLayout.LayoutParams flightDetailsLayout = 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);
    for(int i=0;i < 13;i++){
        LinearLayout flightInformations=(LinearLayout)inflater.inflate(R.layout.flight_details_layout, null);
        flightResult.addView(flightInformations);
    }
}
Developer
  • 6,292
  • 19
  • 55
  • 115
  • is it not possible to use listviews instead? – Andro Selva Aug 05 '13 at 12:08
  • @AndroSelva no i have to use linear layouts see the image link that i have posted u will easily understand what i have to do – Developer Aug 05 '13 at 12:09
  • @Gaurav use a listview add the linear layouts as header and footer. i have suggested the same before and i am suggesting it now also. Actually use a gridview. add the header and footer to the gridview. Recommend using a gridview. – Raghunandan Aug 05 '13 at 13:13
  • @Raghunandan pls see the image link that i have added .how could i do this with listview.and the flight details is in different layout as u see the code i am inflating it at run time – Developer Aug 05 '13 at 13:16
  • i just want a scroll view on both side that scroll independently each layout – Developer Aug 05 '13 at 13:17
  • @Gaurav why can't you use a listview/gridview? you can inflatea custom layout for each row in the listview. listview/gridview handles the scroll. I don't understand why you can use listview/griview?. I have checked the image before posting my suggestion. – Raghunandan Aug 05 '13 at 13:17
  • i just want a help from u to put scroll on both side – Developer Aug 05 '13 at 13:19
  • @Gaurav i am not aware of that. sorry i can't help you further. but i am at loss as to why you can't use a listview or gridview.? what is your reason? – Raghunandan Aug 05 '13 at 13:20
  • so help me how could i do this in listview /gridview .i am new android so if u help me i will be thankfull to u – Developer Aug 05 '13 at 13:21
  • @Gaurav study custom listview http://theopentutorials.com/tutorials/android/listview/android-custom-listview-with-image-and-text-using-arrayadapter/ . check this http://stackoverflow.com/questions/15261088/gridview-with-two-columns-and-auto-resized-images – Raghunandan Aug 05 '13 at 13:24
  • @Gaurav you are welcome the first link does not open. you can google search the same as custom listview. use a gediview with a image and text and the linear layouts and header and footer that should help. – Raghunandan Aug 05 '13 at 13:30
  • i have already seen that ....i have used that but these are not working for me still thank u very much – Developer Aug 05 '13 at 13:31
  • @Gaurav why is that not working for you. post your code. Still want yo use scrollview go ahead with it. – Raghunandan Aug 05 '13 at 14:28
  • @Raghunandan as u r suggestion i am trying to use ListView for my page can u help me with sample code how could i do this.i have seen also the example but i am not able to implement them for my layout ..please help me i need a start how to use that – Developer Aug 06 '13 at 05:27
  • @Gaurav form the picture you have a back button while android has hardware back button that does the job. Secondly use a gridview with textview's and imageview. with two culumns. Add the other linearlayout as a header and a footer. for the sample i don't have time to code for your layout. If i have time i will post the solution – Raghunandan Aug 06 '13 at 05:33
  • @Raghunandan i have done that through a Scroll View but i am facing one issues can help me out on that – Developer Aug 06 '13 at 09:15

2 Answers2

1

I think you need a simple, two-column organization:

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

    <!-- stuff goes here that should appear above the scrolling areas -->

    <ScrollView
        android:id="@+id/left_side_scroller"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1" >

        <!-- contents of left side go here -->
    </ScrollView>

    <ScrollView
        android:id="@+id/right_side_scroller"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1" >

        <!-- contents of right side go here -->
    </ScrollView>

    <!-- stuff goes here that should appear below  the scrolling areas -->
</LinearLayout>

Alternatively (and perhaps better) it looks like you should be using two ListView elements instead of two ScrollView elements. Each ListView would have the same layout parameters as shown above for the ScrollView. Since a ListView manages scrolling internally, you then don't need ScrollView at all.

Also, you probably want the entire layout to fill the screen, with the "filter" and "sort" elements always at the bottom. To achieve this effect,the top-level layout should have android:layout_height="fill_parent" instead of "wrap_content". Also, the scrollable areas should have android:layout_height="0dp" and a non-zero weight (which they already do).

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
  • i am new in android can u help me for some sample code how could i use listview for my design that have two layouts on left and right side – Developer Aug 06 '13 at 06:27
  • @Gaurav - Take a look at the [guide topic on `List View`](http://developer.android.com/guide/topics/ui/layout/listview.html) to learn how a `ListView` works. It will teach you how to make a layout with a single `ListView`. (You don't want a `ListActivity`, however, because it only deals with a single `ListView`. So don't follow that part of the guide.) Then just substitute two `ListView`s in place of the `ScrollView`s I have in my answer. You'll end up with a layout that has two independently scrolling lists of rows like you want. It's a bit complicated, but so are your requirements. – Ted Hopp Aug 06 '13 at 06:56
0

if you are display your scrollview in Horizontal Linear Layout and given a weight to scrollview then set width of Scrollview to "0dp"

android:layout_width="0dp"

and if it is vertical then

android:layout_height="0dp"

also set your main LinearLayout height to fill parent

Shani Goriwal
  • 2,111
  • 1
  • 18
  • 30