我创建了具有某些图表的PageView。但是我想像某些阅读器一样对页面进行剪贴,当您只能向下滚动时,而对您来说,您只能看到下一页的一部分,而不是整个页面。该怎么做?
ChartPageAdapter.class
public class ChartPageAdapter extends PagerAdapter {
private Context context;
Random random = new Random();
public ChartPageAdapter(Context context) {
this.context = context;
}
@NonNull
@Override
public Object instantiateItem(ViewGroup container, int position) {
LayoutInflater inflater = LayoutInflater.from(context);
ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.chart_layout, container, false);
ChartView chartView = layout.findViewById(R.id.chart2);
chartView.setChartData(getRandomData());
container.addView(layout);
return layout;
}
@Override
public int getCount() {
return 2;
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return view == object;
}
@Override
public void destroyItem(ViewGroup collection, int position, Object view) {
collection.removeView((View) view);
}
public int[] getRandomData() {
int[] array = new int[10];
for (int i = 0; i < array.length; i++) {
array[i] = random.nextInt();
}
return array;
}
}