【问题标题】:Call remove view on Child Parent - Android调用子父级上的删除视图 - Android
【发布时间】:2015-06-29 01:20:18
【问题描述】:

我有一个带有滚动视图、标签宿主、相对布局和列表视图的布局。

看起来像这样

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

所以滚动视图高于一切,然后是tabhost,然后是列表视图和相对布局。 (我知道有人可能会说在滚动视图中有一个列表视图也很糟糕,但我找不到更好的方法来完成我想要完成的任务)。

我试图让我的滚动视图滚动,直到相关布局和选项卡离开屏幕,然后让列表视图滚动接管。

所以当我滚动滚动视图时,滚动视图的第一位工作直到它只是屏幕上的列表视图,然后滚动视图“消失”并且列表视图滚动工作。

我查看了这个 SO question Call removeView() on the child's parent first 并尝试删除滚动视图,然后删除列表视图,然后将其添加回来,但我无法让它工作。

任何帮助或其他方法都会很棒。

如果需要,这里是完整布局,我以编程方式添加列表视图

<?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>

谢谢

【问题讨论】:

    标签: java android list listview scrollview


    【解决方案1】:

    你应该通过获取它来检查你的视图已经有一个父视图 textview.getParent().removeView(textview);。

    然后将其添加为 currentLayout.addview(textview)。

    或者试试这个, LayoutInflater inflater=(LayoutInflater)getSystemService (Context.LAYOUT_INFLATER_SERVICE);

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

    currentLayout.addView(newTagView);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-19
      • 1970-01-01
      • 2011-10-15
      • 1970-01-01
      相关资源
      最近更新 更多