gpt4 book ai didi

android - RecyclerView 的滚动效果

转载 作者:行者123 更新时间:2023-11-30 01:34:32 39 4
gpt4 key购买 nike

我在 Android 应用中使用水平 RecyclerView。
一次在屏幕上显示两个项目 (ImageView)。

为此,我在适配器的 ViewHolder 类中将每个 ImageView 的宽度设置为屏幕的一半:

  public static class ViewHolder extends RecyclerView.ViewHolder { 

private LinearLayout ll_Img;
private ImageView iv_ad;


private ViewHolder(View v) {
super(v);

ll_Img = (LinearLayout) itemView.findViewById(R.id.ll_Img);
ll_Img.getLayoutParams().width = (Utils.getScreenWidth(itemView.getContext()) / 2);

iv_ad = (ImageView) v.findViewById(R.id.iv_main_ad);
}
}

获取屏幕宽度:

public static int getScreenWidth(Context context) {

WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int screenWidth = size.x;

return screenWidth;
}

它工作正常,但我想像在 iOS 上一样实现滚动效果,
每次滑动滚动一个项目,
所以每次滑动后 2 个项目必须适合屏幕宽度。

对了,两个1000字的视频
所以这就是我现在所拥有的: https://drive.google.com/file/d/0B7j1Rf_oUEbLOWk1OUtpWXFpcEE/view?usp=sharing

以及我想要实现的目标(正如我的同事在 iOS 上实现的那样): https://drive.google.com/file/d/0B6B-4-ITg1EQTElNTWsxMWg4aWs/view?usp=sharing

感谢每条建议。

最佳答案

这是一个viewpager,不是一个recyclerview。此链接可能有帮助 https://commonsware.com/blog/2012/08/20/multiple-view-viewpager-options.html

只是为了其他人的利益:

getPageWidth() returns a floating-point number, between 0 and 1, representing the portion of the width of the ViewPager that a given page should take up. By default, the page width is 1, but by overriding this, you can have multiple pages on the screen simultaneously.

关于android - RecyclerView 的滚动效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35272289/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com