android中實(shí)現(xiàn)指針滑動(dòng)的動(dòng)態(tài)效果方法
<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="優(yōu)"
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>
上面這段代碼實(shí)現(xiàn)的布局為
首先,因?yàn)橹羔樣袎褐旅娴臐L動(dòng)條,因此這是一個(gè)framelayout的布局。其次,要實(shí)現(xiàn)指針的勻速滾動(dòng),需要開啟一個(gè)線程,在線程中能夠?qū)崿F(xiàn)利用循環(huán),以及線程的休眠,通過控制指針?biāo)趫D標(biāo)的padding屬性來實(shí)現(xiàn)滾動(dòng)的動(dòng)畫效果
Handler myHandler =new Handler(){
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
//對于c的更改和循環(huán)應(yīng)該是在線程中跑,要不run僅僅執(zhí)行一次,
zhizhen.setPadding(c, 0, 0, 0);
}
};
class MyThread extends Thread{
@Override
public void run() {
//發(fā)送一個(gè)消息,通知主線程改變UI
try {
while(c<=input){
c=c+1;
this.sleep(10);
myHandler.sendEmptyMessage(0);
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
相關(guān)文章
Android開發(fā)實(shí)現(xiàn)去除bitmap無用白色邊框的方法示例
這篇文章主要介紹了Android開發(fā)實(shí)現(xiàn)去除bitmap無用白色邊框的方法,結(jié)合實(shí)例形式給出了Android去除bitmap無用白色邊框的具體操作步驟與相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-11-11Android Studio和阿里云數(shù)據(jù)庫實(shí)現(xiàn)一個(gè)遠(yuǎn)程聊天程序
本文主要介紹了Android Studio和阿里云數(shù)據(jù)庫實(shí)現(xiàn)一個(gè)遠(yuǎn)程聊天程序,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-11-11Android中利用NetworkInfo判斷網(wǎng)絡(luò)狀態(tài)時(shí)出現(xiàn)空指針(NullPointerException)問題的解決
這篇文章主要介紹了Android中利用NetworkInfo判斷網(wǎng)絡(luò)狀態(tài)時(shí)出現(xiàn)空指針(NullPointerException)問題的解決方法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-11-11Android開發(fā)之開發(fā)者頭條(一)啟動(dòng)頁實(shí)現(xiàn)
這篇文章主要介紹了Android開發(fā)之開發(fā)者頭條(一)啟動(dòng)頁實(shí)現(xiàn)的相關(guān)資料,需要的朋友可以參考下2016-04-04Android SQLite數(shù)據(jù)庫徹底掌握數(shù)據(jù)存儲(chǔ)
這篇文章主要介紹了 Android SQLite數(shù)據(jù)庫的相關(guān)資料,這里對Android SQLlite做了詳細(xì)介紹,需要的朋友可以參考下2016-10-10Android開發(fā)中Widget的生命周期實(shí)例分析
這篇文章主要介紹了Android開發(fā)中Widget的生命周期,結(jié)合實(shí)例形式分析了Android開發(fā)中Widget生命周期所涉及的常用方法與使用技巧,代碼備有詳盡的注釋便于理解,需要的朋友可以參考下2016-02-02