我有一个与TabLayout链接的ViewPager,它们都在ScrollView内,ViewPager有一个PagerAdapter,在运行时添加了视图,但问题是ScrollView没有垂直滚动,我尝试使用不同的高度ViewPager和TabLayout但它没有工作我检查了一堆有关该主题的问题,但没有一个建议对我有用ViewPager有一个视图列表但我不想使用Recycler视图或ListView因为我希望整个屏幕滚动而不仅仅是ViewPager。
这里是片段的 列表项的xml布局 和ViewPager的PagerAdapter(我在运行时添加视图) 提前感谢您的所有时间和精力:)<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
app:tabSelectedTextColor="@color/white"
app:tabTextColor="@color/dark_gray"
/>
<android.support.v4.view.ViewPager
android:id="@+id/character_info_view_pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
/>
</android.support.design.widget.AppBarLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/list_item_icon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:layout_weight="5"
tools:src="@color/dark_gray"
/>
<TextView
android:id="@+id/list_item_name_text_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="18dp"
android:paddingBottom="18dp"
android:layout_marginLeft="6dp"
tools:text="Item Name goes here"
/>
</LinearLayout>
private class MyPagerAdapter extends PagerAdapter
{
@Override
public Object instantiateItem(ViewGroup container, int position)
{
LinearLayout itemsContainer = new LinearLayout(getActivity());
itemsContainer.setOrientation(LinearLayout.VERTICAL);
for (int i = 0; i < ProfileInfoItems.getSize(position); i++)
{
LinearLayout item = (LinearLayout) LayoutInflater.from(getActivity()).inflate(R.layout.list_item_info_view, container, false);
TextView itemTitle = (TextView) item.findViewById(R.id.list_item_name_text_view);
ImageView itemIcon = (ImageView) item.findViewById(R.id.list_item_icon);
itemTitle.setText(ProfileInfoItems.getName(position, i));
itemIcon.setImageDrawable(getResources().getDrawable(ProfileInfoItems.getIcon(position, i)));
itemsContainer.addView(item, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
}
itemsContainer.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
container.addView(itemsContainer);
return itemsContainer;
}
@Override
public boolean isViewFromObject(View view, Object object)
{
return view == object;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object)
{
container.removeView((View) object);
}
@Override
public int getCount()
{
return TAB_LABELS.length;
}
}