iis服务器助手广告广告
返回顶部
首页 > 资讯 > 移动开发 >android中实现指针滑动的动态效果方法
  • 282
分享到

android中实现指针滑动的动态效果方法

方法指针动态Android 2022-06-06 10:06:32 282人浏览 安东尼
摘要

代码如下:<FrameLayout           

代码如下:
<FrameLayout
            Android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#fff"
            android:paddingBottom="5dp"
            android:paddingLeft="5dp"
            android:paddingRight="2dp"
            >

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:src="@drawable/up_icon"
                android:layout_marginTop="0dp"
                android:paddingTop="0dp" />

            <LinearLayout
                android:layout_width="240dip"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="7dp"
                android:orientation="horizontal" >

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="left"
                    android:text="优"
                    android:textSize="12sp" />

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="left"
                    android:text="良"
                    android:textSize="12sp" />

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="left"
                    android:text="中等"
                    android:textSize="12sp" />

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="left"
                    android:text="不健康"
                    android:textSize="12sp" />

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="left"
                    android:text="有毒害"
                    android:textSize="12sp" />
            </LinearLayout>
           
            <LinearLayout
                android:layout_width="240dip"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="7dp"
                android:layout_marginTop="40dp"
                android:orientation="horizontal" >

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center_horizontal"
                    android:text="80"
                    android:textSize="12sp" />

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center_horizontal"
                    android:text="120"
                    android:textSize="12sp" />

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center_horizontal"
                    android:text="160"
                    android:textSize="12sp" />

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center_horizontal"
                    android:text="200"
                    android:textSize="12sp" />

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center_horizontal"
                    android:text="400"
                    android:textSize="12sp" />
            </LinearLayout>

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="10dp"
                android:src="@drawable/zhizhen"
                android:id="@+id/zhizhen"/>

            <ImageView
                android:id="@+id/dengji_img"
                android:layout_width="250dip"
                android:layout_height="wrap_content"
                android:layout_marginTop="25dp"
                android:src="@drawable/dengji_icon" />
        </FrameLayout>

上面这段代码实现的布局为

首先,因为指针有压着下面的滚动条,因此这是一个framelayout的布局。其次,要实现指针的匀速滚动,需要开启一个线程,在线程中能够实现利用循环,以及线程的休眠,通过控制指针所在图标的padding属性来实现滚动的动画效果

代码如下:
Handler myHandler =new Handler(){

        @Override
        public void handleMessage(Message msg) {
            // TODO Auto-generated method stub
            super.handleMessage(msg);
            //对于c的更改和循环应该是在线程中跑,要不run仅仅执行一次,           
            zhizhen.setPadding(c, 0, 0, 0);
        }
       
    };
    class MyThread extends Thread{

        @Override
        public void run() {
            //发送一个消息,通知主线程改变UI
         try {
             while(c<=input){
                 c=c+1;
                 this.sleep(10);
                 myHandler.sendEmptyMessage(0);                
             }
               
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

您可能感兴趣的文章:Android使用ViewPager实现无限滑动效果Android中实现监听ScrollView滑动事件android开发教程之实现滑动关闭fragment示例Android利用ViewPager实现滑动广告板实例源码android中使用Activity实现监听手指上下左右滑动android 获取视频,图片缩略图的具体实现android使用videoview播放视频Android播放视频的三种方式Android使用VideoView播放本地视频和网络视频的方法Android仿新浪微博/QQ空间滑动自动播放视频功能


--结束END--

本文标题: android中实现指针滑动的动态效果方法

本文链接: https://www.lsjlt.com/news/27902.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作