بروز خطا
[message]
اشتراک در سوال
رای ها
[dataList]
نحوه ساخت ساعت آنالوگ
با سلام
تا اونجایی که می دانم این کار را باید با استفاده از کنترل سفارشی انجام بدهم. البته اگر درست بدانم، اگر خطی را به عنوان عقربه ساعت در دایره ای نمایش دهیم حال نمی توانم مکان جدید عقربه بعد از یک ثانیه یا یک دقیقه یا یک ساعت را محاسبه کنم یعنی فرمول محاسبه مکان جدید عقربه ها رو نمی توانم بدست بیاورم
اگر کسی می تواند راهنمایی کند با تشکر
برای این سوال 1 پاسخ وجود دارد.
پاسخ به سوال
atf
10 سال پیش
+2
0
تو لایه ای که میخوای ساعت رو درست کنی اینو بزار
<AnalogClock
android:id="@+id/AnalogClock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:dial="@drawable/cir_blue_small"
android:hand_hour="@drawable/clock_hour_hand"
android:hand_minute="@drawable/clock_minute_hand" >
</AnalogClock>
<ImageView
android:id="@+id/imgsecond"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/clock_second_hand" />
تو کلاس جاوا اینو بزار
ImageView img;
Handler mHandler;
public void doRotate() {
runOnUiThread(new Runnable() {
public void run() {
try {
Date dt = new Date();
int hours = dt.getHours();
int minutes = dt.getMinutes();
int seconds = dt.getSeconds();
String curTime = hours + ":" + minutes + "::" + seconds;
Log.v("log_tag", "Log is here Time is now" + curTime);
img = (ImageView) findViewById(R.id.imgsecond);
RotateAnimation rotateAnimation = new RotateAnimation(
(seconds - 1) * 6, seconds * 6,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setInterpolator(new LinearInterpolator());
rotateAnimation.setDuration(1000);
rotateAnimation.setFillAfter(true);
img.startAnimation(rotateAnimation);
} catch (Exception e) {
}
}
});
}
class CountDownRunner implements Runnable {
// @Override
public void run() {
while (!Thread.currentThread().isInterrupted()) {
try {
doRotate();
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (Exception e) {
Log.e("log_tag", "Error is " + e.toString());
}
}
}
}
تو oncreate هم اینو بزار
Thread myThread = null;
Runnable runnable = new CountDownRunner();
myThread = new Thread(runnable);
myThread.start();
پایان
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .