Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android xamarin中滚动视图中的Listview_Android_Listview_Android Listview_Xamarin_Scrollview - Fatal编程技术网

Android xamarin中滚动视图中的Listview

Android xamarin中滚动视图中的Listview,android,listview,android-listview,xamarin,scrollview,Android,Listview,Android Listview,Xamarin,Scrollview,我是一名windows开发人员。我对安卓系统不太了解。所以我的场景是这样的:我有一个scrollview,它的子对象是线性布局。线性布局有3个列表视图。我想显示所有3个列表视图中的所有项目。滚动将由顶级滚动视图处理 这样行吗 <ScrollView android:scrollbars="vertical" android:scrollbarStyle="insideOverlay" android:layout_width="match_parent" a

我是一名windows开发人员。我对安卓系统不太了解。所以我的场景是这样的:我有一个scrollview,它的子对象是线性布局。线性布局有3个列表视图。我想显示所有3个列表视图中的所有项目。滚动将由顶级滚动视图处理

这样行吗

<ScrollView
    android:scrollbars="vertical"
    android:scrollbarStyle="insideOverlay"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/scrollView1"
    android:fadeScrollbars="true">
    <LinearLayout
        android:orientation="vertical"
        android:minWidth="25px"
        android:minHeight="25px"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/linearLayout2">
        <RelativeLayout xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:id="@+id/linear_currentSubEmpty"
            android:layout_height="match_parent">

            <LinearLayout
                android:orientation="vertical"
                android:background="@android:color/transparent"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/currentListViewLayout"
                android:layout_below="@+id/currentSubsView">
                <com.fortysevendeg.swipelistview.SwipeListView xmlns:swipe="http://schemas.android.com/apk/res-auto"
                    android:id="@+id/currentSubList"
                    android:listSelector="#00000000"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    swipe:swipeFrontView="@+id/front"
                    android:background="@android:color/transparent"
                    swipe:swipeBackView="@+id/back"
                    swipe:swipeDrawableChecked="@drawable/choice_selected"
                    swipe:swipeDrawableUnchecked="@drawable/choice_unselected"
                    swipe:swipeCloseAllItemsWhenMoveList="true"
                    swipe:swipeMode="left"
                    swipe:swipeActionLeft="reveal"
                    swipe:swipeOpenOnLongPress="false"
                    android:layout_weight="1" />
            </LinearLayout>
        </RelativeLayout>
        <RelativeLayout
            android:layout_width="match_parent"
            android:id="@+id/pastViewLayout"
            android:layout_height="match_parent">

            <RelativeLayout xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:id="@+id/linear_pastSubEmpty"
                android:layout_height="wrap_content"
                android:layout_below="@+id/pastBottomView">
                <ListView
                    android:minWidth="25px"
                    android:minHeight="25px"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/pastSubList"
                    android:divider="#ffffffff"
                    android:dividerHeight="1dp"
                    android:layout_weight="1" />
            </RelativeLayout>
        </RelativeLayout>
        <RelativeLayout
            android:layout_width="match_parent"
            android:id="@+id/suspViewLayout"
            android:layout_height="match_parent">

            <RelativeLayout xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:id="@+id/linear_suspendedSubEmpty"
                android:layout_height="wrap_content"
                android:layout_below="@+id/suspBottomView">
                <ListView
                    android:minWidth="25px"
                    android:minHeight="25px"
                    android:id="@+id/suspSubList"
                    android:divider="#ffffffff"
                    android:dividerHeight="1dp"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />
            </RelativeLayout>
        </RelativeLayout>
    </LinearLayout>
</ScrollView>

我知道没有直接的方法来实现这一点,我遵循了以下方法

public static void SetListViewHeightBasedOnChildren(ListView listView) {
        IListAdapter listAdapter = listView.Adapter;
        if (listAdapter == null) {
            return;
        }

        int totalHeight = listView.PaddingTop + listView.PaddingBottom;
        for (int i = 0; i < listAdapter.Count; i++) {
            View listItem = listAdapter.GetView(i, null, listView);
            if (listItem is ViewGroup) {
                listItem.LayoutParameters = new global::Android.Views.ViewGroup.LayoutParams (global::Android.Views.ViewGroup.LayoutParams.WrapContent, global::Android.Views.ViewGroup.LayoutParams.WrapContent);
            }
            listItem.Measure(0, 0);
            totalHeight += listItem.MeasuredHeight;
        }

        global::Android.Views.ViewGroup.LayoutParams parameters = listView.LayoutParameters;
        parameters.Height = totalHeight + (listView.DividerHeight * (listAdapter.Count - 1));
        listView.LayoutParameters = parameters;
    }
public static void SetListViewHeightBasedOnChildren(ListView ListView){
IListAdapter listAdapter=listView.Adapter;
如果(listAdapter==null){
返回;
}
int totalHeight=listView.PaddingTop+listView.PaddingBottom;
对于(int i=0;i