我想将viewpager放在NestedScrollView内,除非我给viewpager的高度指定一个数字(例如200dp),否则它不会显示内容。
我尝试将layout_height
的值放入match_parent
,但仍然不起作用。它只需要一个特定的数字
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v4.view.ViewPager
android:id="@+id/ff"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
和我的.java文件
public class Adaptor extends PagerAdapter {
Activity activity;
ArrayList f;
public Adaptor(Activity a, ArrayList g){
activity=a;
f=g;
}
@Override
public int getCount() {
return f.size();
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
return view==o;
}
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
LayoutInflater layoutInflater=(LayoutInflater)activity.getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view=layoutInflater.inflate(R.layout.fragment,container,false);
TextView textView=(TextView)view.findViewById(R.id.ll);
textView.setText(f.get(position)+"fdfdfd "+position);
container.addView(view);
return view;
}
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
((ViewPager) container).removeView((View) object);
}
}