【发布时间】:2017-12-21 12:01:17
【问题描述】:
视图中的所有应用一次显示 3 个应用,第 4 个是预览。向左滑动时,应用程序将移动并放置在相应的位置,使视图更酷。!
请帮助我实现这个观点。
public class PageAdapter extends PagerAdapter {
View itemView;
Context context;
LayoutInflater inflater;
ArrayList<String> arrayList = new ArrayList<>();
public PageAdapter(Context context, ArrayList<String> arrayList) {
this.context = context;
this.arrayList = arrayList;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
if (inflater == null)
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.item_page, container, false);
TextView textView = view.findViewById(R.id.text_item);
Log.i("Position>>>>>>>> ", "" + position);
textView.setText(arrayList.get(position));
container.addView(view);
return view;
}
@Override
public int getCount() {
return arrayList.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public void destroyItem(ViewGroup collection, int position, Object view) {
collection.removeView((View) view);
}
View getLayoutView() {
if (itemView != null)
return itemView;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
itemView = inflater.inflate(R.layout.item_page, null);
return itemView;
}
}
【问题讨论】:
-
最有可能的是,那些没有使用
ViewPager,而是使用RecyclerView,甚至可能是HorizontalScrollView。 -
但是添加 HorizontalScrollView 将使滚动更平滑,我希望项目在移动时与前一个项目位于同一位置。
-
你
RecyclerView和HorizontalLayoutManage和 snaphelper -
使用
ViewPager在视图之间切换(例如家庭、游戏、电影)。使用RecyclerViews显示页面内的项目 -
CommonsWare 是对的——他们用
RecyclerView做到了——使用<sdk_root>/tools/bin/uiautomatorviewer来查看 UI 树
标签: android android-layout android-viewpager