国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

android中實現指針滑動的動態效果

2020-02-21 17:30:55
字體:
來源:轉載
供稿:網友

今天這篇文章是android中實現指針滑動的動態效果,它是打開線程并控制指針所在的ImageView控件的padding屬性,下面就跟著武林技術頻道小編的步伐來學習吧!


<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中實現指針滑動的動態效果,相信認真看完的朋友都已經懂了,看了小編的介紹之后趕快收藏起來吧!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 穆棱市| 库伦旗| 汉阴县| 瑞金市| 大庆市| 师宗县| 年辖:市辖区| 丹棱县| 南康市| 苍南县| 缙云县| 监利县| 汤原县| 固原市| 习水县| 微山县| 靖远县| 乐至县| 渭南市| 宣化县| 东阿县| 岳普湖县| 青龙| 海门市| 望城县| 天祝| 五台县| 农安县| 普兰店市| 安远县| 阿鲁科尔沁旗| 太保市| 苗栗县| 土默特左旗| 万宁市| 内丘县| 沿河| 苏尼特左旗| 凌云县| 宾川县| 奉节县|