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

2016-02-19 10:20 52 1 收藏

岁数大了,QQ也不闪了,微信也不响了,电话也不来了,但是图老师依旧坚持为大家推荐最精彩的内容,下面为大家精心准备的android中实现指针滑动的动态效果方法,希望大家看完后能赶快学习起来。

【 tulaoshi.com - 编程语言 】

代码如下:

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"

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

                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(){

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

        @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();
        }

来源:https://www.tulaoshi.com/n/20160219/1594276.html

延伸阅读
iPhone6如何减少动态效果 &nbTulaoshi.Comsp; 1)在iPhone6的【设置】里选择【通用】,然后选择【辅助功能】。 &nbwww.Tulaoshi.comsp; 2)然后找到并点击【减少动态效果】,把【减少动态效果】打开就好了。   iphone6来电闪光灯怎么设置?   iphone6来电闪光灯怎么设置?iphone6的来电闪光灯是一个非常人性化的功...
iPhone6怎么减少动态效果   iPhone6减少动态效果方法?iPhone6的一些动态效果虽然可以让手机看起来更高大上,但带来的是耗电量的增加,下面呢,图老师小编就来告诉大家iPhone6减少动态效果方法,一起来看吧。 1)在iPhone6的【设置】里选择【通用】,然后选择【辅助功能】。(如下图)   2)然后找到并点击【减少动态效...
标签: PS PS教程
PHOTOSHOP CS3版本以上直接制作!!!!!!!!! 先看看效果吧 因为有的朋友不太了解IR,所以粥粥会很唠叨,(*^__^*) 嘻嘻…… 以第一款为例,首先,在PS里做好这样一张图保存为GIF或者是PNG,(粥粥会把自己收集来的像素坠子笔刷和大家分享,在帖子最下面)这样背景就是透明的了,现在命名它为98PS 第二步,将下...
使用方法是这样的,Activity.showDialog()激发Activity.onCreateDialog()创建Dialog,然后显示之,便于多个Dialog的统一管理。 注意,以后再用Activity.showDialog()显示同一个Dialog时,则不会调用Activity.onCreateDialog(), 而是调用Activity.onPrepareDialog(),使用上一次显示Dialog时的状态。即      第一次:sh...
滑动控件是Windows中最常用的控件之一。一般而言它是由一个滑动条,一个滑块和可选的刻度组成,用户可以通过移动滑块在相应的控件中显示对应的值。通常,在滑动控件附近一定有标签控件或编辑框控件,用于显示相应的值。滑动控件在应用程序中用途级为广泛,如在桌面的属性中就可以看到。为此,让我们一起来看一下它的实现方法。 (...

经验教程

185

收藏

29
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部