viewpager未在可滚动布局下显示

时间:2018-05-16 01:39:12

标签: android xamarin.android android-viewpager

更新样本

enter image description here

我的目标是在ExpandableListView下实现一个viewpager。我试着编码它但它没有显示。我也尝试在ScrollView下实现它来测试一些东西和相同的结果。我想这是因为2个可滚动的布局同时?到现在为止,我找到了一个带有viewpager的ScrollView解决方案。当我添加 android:fillViewport =" true" 时,它工作正常,我现在可以看到它内部的viewpager。

如何在ExpandableListView下实现viewpager?它没有 android:fillViewport = true"" ,除了它可以使用什么?

以下是xml布局。

这是我必须添加我的viewpager

的地方
    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="37"
        android:background="@color/whiteWithAlpha75">
        <ExpandableListView
            android:minWidth="25px"
            android:minHeight="25px"
            android:childDivider="@drawable/childSeparator"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingBottom="1dp"
            android:id="@+id/expandableListView" />
    </LinearLayout>

这是我的ExpandableListAdapter

using System;
using System.Collections.Generic;

using Android.App;
using Android.Views;
using Android.Widget;
using Android.Graphics;
using ENTITIES;
using System.Linq;
using Android.Support.V4.Content;
using Android.Support.V4.View;

namespace H2POS
{

    class CategoryItemExpandableAdapter : BaseExpandableListAdapter
    {
        private Activity activity;
        private List<ENT_DataEntries> categoryList;
        List<ViewPager> viewPagerList;

        public CategoryItemExpandableAdapter(Activity activity, List<ENT_DataEntries> categoryList, List<ViewPager> viewPagerList) : base()
        {
            this.activity = activity;
            this.categoryList = categoryList;
            this.viewPagerList = viewPagerList;
        }

        public override int GroupCount
        {
            get
            {
                return categoryList.Count;
            }
        }

        public override bool HasStableIds
        {
            get
            {
                return true;
            }
        }

        public override Java.Lang.Object GetChild(int groupPosition, int childPosition)
        {
            return childPosition;
        }

        public override long GetChildId(int groupPosition, int childPosition)
        {
            return childPosition;
        }

        public override int GetChildrenCount(int groupPosition)
        {
            return 1;
        }

        public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent)
        {
            try
            {
                var row = convertView;

                if (row == null)
                {
                    row = LayoutInflater.From(activity).Inflate(Resource.Layout.Layout_LinearVertical, null);
                    LinearLayout llLinearViewPager = row.FindViewById<LinearLayout>(Resource.Id.llLinearViewPager);

                    //This is for testing. This is showing
                    TextView tvSample = new TextView(activity);
                    tvSample.SetHeight(50);
                    tvSample.SetWidth(50);
                    tvSample.Text = "Sample";
                    llLinearViewPager.AddView(tvSample);

                    //This is my view pager. This is not showing
                    //I tried to attach it to other layout and it is showing there
                    if(viewPagerList[groupPosition].Parent == null)
                        llLinearViewPager.AddView(viewPagerList[groupPosition]);
                }

                return row;
            }
            catch (Exception e)
            {
                UIHelper.ToastMessage(activity.BaseContext, "Error on expandable adapter");
            }

            return new View(activity);
        }

        public override Java.Lang.Object GetGroup(int groupPosition)
        {
            throw new NotImplementedException();
        }

        public override long GetGroupId(int groupPosition)
        {
            return groupPosition;
        }

        public override View GetGroupView(int groupPosition, bool isExpanded, View convertView, ViewGroup parent)
        {
            View row = convertView;

            if (row == null)
            {
                row = LayoutInflater.From(activity).Inflate(Resource.Layout.Layout_Category, null);
            }

            //set header text
            TextView categoryHeader = row.FindViewById<TextView>(Resource.Id.tvCategoryName);
            categoryHeader.Text = categoryList[groupPosition].Description;
            categoryHeader.SetTypeface(Typeface.Default, TypefaceStyle.Bold);

            if (isExpanded)
                categoryHeader.SetBackgroundColor(new Color(ContextCompat.GetColor(activity, Resource.Color.baseColorLightWithAlpha10)));
            else
                categoryHeader.SetBackgroundColor(new Color(ContextCompat.GetColor(activity, Resource.Color.whiteWithAlpha10)));

            return row;
        }

        public override bool IsChildSelectable(int groupPosition, int childPosition)
        {
            return true;
        }
    }
}

这是我成功在ScrollView下显示viewpager的地方。我在llItemSelectedArea

下添加了viewpager
            <ScrollView
                android:id="@+id/scrollItemSelectedArea"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="95"
                android:paddingBottom="-65dp"
                android:fillViewport="true"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                android:background="@color/whiteWithAlpha15">
                <LinearLayout
                    android:id="@+id/llItemSelectedArea"
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:paddingBottom="65dp" />
            </ScrollView>

1 个答案:

答案 0 :(得分:-1)

我认为,你无法将这两个小部件结合起来。这对我来说毫无意义