0

I have a layout with a scroll view, a tab host, relative layout and a list view.

Looks something like this

scrollView
    tabHost
        relative layout
        (the tabs are here for switching the list view)
        listview

So the scrollview is above everything, and then the tabhost, and then the list view and relative layout are inside it. (I know someone might say its bad too have a list view inside a scroll view but I can't find a better way to do what Im trying to accomplish).

Im trying to have my scroll view scroll, until the relative layout and tabs are off the screen, and then have the list view scroll take over.

So when I scroll the scroll view works for the first bit until its just the list view on the screen and then the scroll view "disappears" and the list view scroll works.

I have looked at this SO question Call removeView() on the child's parent first and have tried removing the scrollview and then the list view, and then adding it back but I can't get it to work.

Any help or another way to do this would be great.

Here is full layout if needed, I add the list view programtically

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/rl">
    <ScrollView android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/scrollView">
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:id="@+id/linearLayout">

            <TabHost
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:id="@+id/TabHost01">

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

                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="50dp"
                        android:background="#ff00f1ff">

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Sunday June 27, 2015"
                            android:id="@+id/currentDayTextview"
                            android:textSize="22sp"
                            android:textColor="#ffffff"
                            android:textStyle="bold"
                            android:layout_centerVertical="true"
                            android:layout_centerHorizontal="true" />

                        <ImageView
                            android:layout_width="60dp"
                            android:layout_height="60dp"
                            android:id="@+id/nextDayArrow"
                            android:background="@drawable/next_day_arrow"
                            android:layout_alignParentBottom="true"
                            android:layout_alignParentRight="true"
                            android:layout_alignParentEnd="true"
                            android:layout_alignParentTop="true"
                            android:layout_toEndOf="@+id/currentDayTextview"
                            android:layout_toRightOf="@+id/currentDayTextview"/>

                        <ImageView
                            android:layout_width="60dp"
                            android:layout_height="60dp"
                            android:id="@+id/previousDayArrow"
                            android:background="@drawable/previous_day_arrow"
                            android:layout_centerVertical="true"
                            android:layout_alignParentLeft="true"
                            android:layout_alignParentStart="true"
                            android:layout_toStartOf="@+id/currentDayTextview"
                            android:layout_toLeftOf="@+id/currentDayTextview"/>

                    </RelativeLayout>



                    <TabWidget
                        android:id="@android:id/tabs"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"/>

                    <FrameLayout
                        android:id="@android:id/tabcontent"
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:layout_weight="1">

                    </FrameLayout>
                </LinearLayout>
            </TabHost>

        </LinearLayout>
    </ScrollView>


</RelativeLayout>

Thanks

Community
  • 1
  • 1
tim blue
  • 138
  • 2
  • 14

1 Answers1

0

You should check your view which has already a parent by getting it like textview.getParent().removeView(textview);.

And then add this as currentLayout.addview(textview).

or else try this, LayoutInflater inflater=(LayoutInflater)getSystemService (Context.LAYOUT_INFLATER_SERVICE);

View newView= inflater.inflate(R.layout.layout, null);

currentLayout.addView(newTagView);

Randyson
  • 59
  • 5