短视频平台源码,Android 左右滑动显示和隐藏
作者:互联网
短视频平台源码,Android 左右滑动显示和隐藏实现的相关代码
private List<Integer> integerList = new ArrayList<>();
for (int i = 0; i < 7; i++) {
integerList.add(i);
}
WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics displayMetrics = new DisplayMetrics();
windowManager.getDefaultDisplay().getMetrics(displayMetrics);
int widthPixels = displayMetrics.widthPixels;
float density = displayMetrics.density;
int screenWidth = (int) (widthPixels / density); //屏幕的宽度
Log.d("TAG","屏幕宽度:"+screenWidth);
int i = 138 * 2; //recycleview距离右侧和左侧的距离
int recywidth = screenWidth - i; //recycleview在屏幕的大小
Log.d("TAG","recycleview 的宽度:"+recywidth);
int entry = recywidth / 370; // 一屏能显示几个条目
Log.d("TAG","一屏幕条目:"+entry);
// integerList集合是添加的多少条数据
if (integerList.size()>entry){ //条目大于屏幕上的显示条目时 显示滚动条否则关闭滚动条
hIndicator.setVisibility(View.VISIBLE); //显示
}else {
hIndicator.setVisibility(View.GONE); //隐藏
}
以上就是 短视频平台源码,Android 左右滑动显示和隐藏实现的相关代码,更多内容欢迎关注之后的文章
标签:int,integerList,条目,源码,displayMetrics,滑动,Android,屏幕 来源: https://www.cnblogs.com/yunbaomengnan/p/15458414.html