久久福利_99r_国产日韩在线视频_直接看av的网站_中文欧美日韩_久久一

您的位置:首頁技術文章
文章詳情頁

Android實現儀表盤控件開發

瀏覽:85日期:2022-09-18 13:34:15

儀表盤在工業軟件中很常見,今天整一個圖片式儀表盤控件(非幾何圖形繪制)。實現非常簡單,一張背景圖,一張指針。創建一個RelativeLayout布局文件,然后在里面布置好控件的位置,代碼如下

<?xml version='1.0' encoding='utf-8'?><RelativeLayout xmlns:android='http://schemas.android.com/apk/res/android' android:layout_width='wrap_content' android:layout_height='wrap_content'> <ImageViewandroid: android:layout_width='wrap_content'android:layout_height='wrap_content'android:layout_centerInParent='true'android:src='http://www.gepszalag.com/bcjs/@mipmap/meter_h_bk' /> <ImageViewandroid: android:layout_width='wrap_content'android:layout_height='wrap_content'android:layout_alignBottom='@id/id_dial'android:layout_centerInParent='true'android:src='http://www.gepszalag.com/bcjs/@mipmap/meter_fr' /> <com.tech.view.DigitalTextandroid: android:layout_width='wrap_content'android:layout_height='wrap_content'android:layout_alignBottom='@id/id_dial'android:layout_centerHorizontal='true'android:layout_marginBottom='2dp'android:text='29.9'android:textColor='@android:color/white'android:textSize='21sp' /></RelativeLayout>

DigitalText是使用第三方字體控件,這個可自行百度搜索想要的字體。然后寫一個儀表盤控件類,DialBoard

代碼如下

public class DialBoard { private static final String TAG = DialBoard.class.getName(); private ImageView dialPoint; private TextView text; private static final float MAX = 120.0f; private static final float MIN = -120.0f; private boolean animationDone = true; public DialBoard(Activity activity) {dialPoint = activity.findViewById(R.id.id_dial_point);text = activity.findViewById(R.id.id_value);text.setText(String.format('%.02f', 0.0f));setRotation(MIN, true); } public synchronized void moveTo(float progress) {if (animationDone) new Thread(() -> move(progress)).start(); } private void move(float progress) {animationDone = false;float offset = (MAX - MIN) / 100;final float STEP = 2.0f;//理論上要小于offsetfloat curProgress = (dialPoint.getRotation() - MIN) / offset;//計算當前進度和目標進度方向,步數float value = Math.abs(curProgress - progress);while (value > 0.1f) { value = (value < 1.0f ? 0.2f : STEP); if (progress < curProgress) value = -value; setRotation(dialPoint.getRotation() + value, false); Tools.sleep(10); curProgress = (dialPoint.getRotation() - MIN) / offset; value = Math.abs(curProgress - progress); final float textValue = curProgress; text.post(() -> text.setText(String.format('%.02f', textValue)));}text.post(() -> text.setText(String.format('%.02f', progress)));animationDone = true; } /** * @param rotation MIN~MAX */ public void setRotation(float rotation) {this.setRotation(rotation, false); } private void setRotation(float rotation, boolean onCreate) {if (onCreate) { int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); dialPoint.measure(w, h);//測量控件大小}int width = dialPoint.getMeasuredWidth();int height = dialPoint.getMeasuredHeight();dialPoint.post(() -> { dialPoint.setPivotX(width * 0.5f); dialPoint.setPivotY(height * 0.82666f); dialPoint.setRotation(rotation);}); }}

最終效果圖

Android實現儀表盤控件開發

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Android
相關文章:
主站蜘蛛池模板: 免费毛片网站 | 国产毛片毛片 | 蜜桃免费视频 | 91在线视频一区 | 久热热 | 国产精品成人一区二区三区夜夜夜 | 欧美一级做性受免费大片免费 | 国产精品一区二区不卡 | 午夜在线视频免费观看 | 国产日韩精品一区二区 | 日本高清无卡码一区二区久久 | 精品欧美一区二区在线观看 | 欧美一区二区免费 | 亚洲免费a | 亚洲一区中文 | 五月天婷婷国产精品 | 久久久久无码国产精品一区 | 精品国产乱码一区二区三区a | 国产xxx护士爽免费看 | 国产精品成人在线 | 国产不卡在线 | 九九热这里只有精品8 | 成人亚洲免费 | 一区二区欧美视频 | 日韩中文字幕一区二区 | 国产一区二区观看 | 国产h视频在线观看 | 国偷自产av一区二区三区 | 91视频免费观看网址 | 日本高清h色视频在线观看 日日干日日操 | 逼逼av | 午夜寂寞影视在线观看 | 亚州国产精品 | 精品视频在线免费观看 | 美女天堂 | 久久久久91 | 免费高清av| 国产一区久久 | 久久婷婷色 | 国产成人视屏 | 国产精品成人一区二区三区夜夜夜 |