实习笔记2

retrofit

在安卓中显示gif图片

使用WebView

<WebView
    android:id="@+id/runWebView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true" />
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

    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的宽度

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)
}

自定义下拉刷新(没学会)

  • TRANSLUCENT 半透明

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(翻转视图)

  • 就是首次安装软件后的功能介绍页面

使用

导入图片

    <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>
//动态导入
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
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);
}
//自动翻动
vflp_help.startFlipping();

fragment中实现触摸事件

参考

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容