在安卓中显示gif图片
使用WebView
1 2 3 4 5 6 <WebView android:id ="@+id/runWebView" android:layout_width ="wrap_content" android:layout_height ="wrap_content" android:layout_centerHorizontal ="true" android:layout_centerVertical ="true" />
1 2 3 4 5 6 7 8 runWebView.loadDataWithBaseURL(null , "<html> <body bgcolor='#f3f3f3'> <div align=center> <IMG src='file:///android_asset/run.gif'/> </div> </body> </html>" , "text/html" , "UTF-8" ,null );
实现底部状态栏
使用recyclerview + gridlayoutmanager
1 2 3 4 5 val rc_btm_navi = findViewById<RecyclerView>(R.id.rc_btm_navi)rc_btm_navi.layoutManager = GridLayoutManager(this ,1 ).apply { orientation = GridLayoutManager.HORIZONTAL } rc_btm_navi.adapter = navi_adapter()
adaper中获取屏幕宽度,创建view时设置view的宽度
1 2 3 4 5 6 7 8 9 10 11 override fun onCreateViewHolder (parent: ViewGroup , viewType: Int ) : view_holder { val view: View = LayoutInflater.from(parent.context) .inflate( R.layout.item_navi, parent, false ) view.layoutParams.width = getScreenWidth(activity) / navi_arr.size return view_holder(view) }
自定义下拉刷新(没学会)
rectF类
Rect F holds four float coordinates for a rectangle . The rectangle
is represented by the coordinates of its 4 edges ( left , top , right
bottom ). These fields can be accessed directly . Use width () and
height () to retrieve the rectangle ’ s width and height . Note :
most methods do not check to see that the coordinates are sorted
correctly ( i . e . left <= right and top <= bottom ).
ViewFlipper(翻转视图)
使用
导入图片
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <ViewFlipper android:id ="@+id/vflp_help" android:layout_width ="match_parent" android:layout_height ="match_parent" android:inAnimation ="@anim/right_in" android:outAnimation ="@anim/right_out" android:flipInterval ="3000" > <include layout ="@layout/page_help_one" /> <include layout ="@layout/page_help_two" /> <include layout ="@layout/page_help_three" /> <include layout ="@layout/page_help_four" /> </ViewFlipper >
1 2 3 4 5 6 7 8 9 for (int i = 0 ;i < resId.length;i++){ vflp_help.addView(getImageView(resId[i])); } private ImageView getImageView(int resId){ ImageView img = new ImageView(this ); img.setBackgroundResource(resId); return img; }
翻动
手动翻动
自定义一个GestureListener
创建一个GestureDetector
重写activity的onTouchEvent
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 private class MyGestureListener extends GestureDetector .SimpleOnGestureListener { @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float v, float v1) { if (e1.getX() - e2.getX() > MIN_MOVE){ vflp_help.setInAnimation(mContext,R.anim.right_in); vflp_help.setOutAnimation(mContext, R.anim.right_out); vflp_help.showNext(); }else if (e2.getX() - e1.getX() > MIN_MOVE){ vflp_help.setInAnimation(mContext,R.anim.left_in); vflp_help.setOutAnimation(mContext, R.anim.left_out); vflp_help.showPrevious(); } return true ; } } @Override public boolean onTouchEvent(MotionEvent event) { return mDetector.onTouchEvent(event); }
1 2 vflp_help.startFlipping();
fragment中实现触摸事件
参考