안 드 로 이 드 모방 경 동 초살 카운트다운 코드
내 가 모방 한 경 동 은 분 모듈 이기 때문에 이번 에는 주로 초살 모듈 을 묘사 합 니 다!
우선 시간의 배경 을 설정 해 주세요.
drawable 파일 아래 shape 만 들 기miaosha_time.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#000"></solid>
<corners android:radius="2.5dp"></corners>
</shape>
그리고 주요 구 조 는 단독으로 쓴 다음 에 인용 할 수 있다
**count_down.xml**
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center_vertical">
<TextView
android:id="@+id/tv_miaosha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:text=" "
android:textColor="#f00"
android:textSize="20sp" />
<TextView
android:id="@+id/tv_miaosha_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="12 "
android:textSize="20sp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_miaosha_shi"
android:layout_width="25dp"
android:layout_height="25dp"
android:background="@drawable/shape_miaosha_time"
android:gravity="center"
android:text="1"
android:textColor="#fff"
android:textSize="15sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:text=":" />
<TextView
android:id="@+id/tv_miaosha_minter"
android:layout_width="25dp"
android:layout_height="25dp"
android:background="@drawable/shape_miaosha_time"
android:gravity="center"
android:text="1"
android:textColor="#fff"
android:textSize="15sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:text=":" />
<TextView
android:id="@+id/tv_miaosha_second"
android:layout_width="25dp"
android:layout_height="25dp"
android:background="@drawable/shape_miaosha_time"
android:gravity="center"
android:text="1"
android:textColor="#fff"
android:textSize="15sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
논리 코드 여기 써 있어 요.
// handler UI
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
countDown();
sendEmptyMessageDelayed(0, 1000);
}
};
/**
*
*/
private void countDown() {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date curDate = new Date(System.currentTimeMillis());
String format = df.format(curDate);
StringBuffer buffer = new StringBuffer();
String substring = format.substring(0, 11);
buffer.append(substring);
Log.d("ccc", substring);
Calendar calendar = Calendar.getInstance();
int hour = calendar.get(Calendar.HOUR_OF_DAY);
if (hour % 2 == 0) {
mMiaoshaTimeTv.setText(hour + " ");
buffer.append((hour + 2));
buffer.append(":00:00");
} else {
mMiaoshaTimeTv.setText((hour - 1) + " ");
buffer.append((hour + 1));
buffer.append(":00:00");
}
String totime = buffer.toString();
try {
java.util.Date date = df.parse(totime);
java.util.Date date1 = df.parse(format);
long defferenttime = date.getTime() - date1.getTime();
long days = defferenttime / (1000 * 60 * 60 * 24);
long hours = (defferenttime - days * (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);
long minute = (defferenttime - days * (1000 * 60 * 60 * 24) - hours * (1000 * 60 * 60)) / (1000 * 60);
long seconds = defferenttime % 60000;
long second = Math.round((float) seconds / 1000);
mMiaoshaShiTv.setText("0" + hours + "");
if (minute >= 10) {
mMiaoshaMinterTv.setText(minute + "");
} else {
mMiaoshaMinterTv.setText("0" + minute + "");
}
if (second >= 10) {
mMiaoshaSecondTv.setText(second + "");
} else {
mMiaoshaSecondTv.setText("0" + second + "");
}
} catch (ParseException e) {
e.printStackTrace();
}
}
여기 가 오픈 코드 입 니 다.
private void startCountDown() {
handler.sendEmptyMessage(0);
}
총결산위 에서 말 한 것 은 편집장 이 여러분 에 게 소개 한 안 드 로 이 드 모방 경 동 초읽기 코드 입 니 다.여러분 에 게 도움 이 되 기 를 바 랍 니 다.궁금 한 점 이 있 으 면 메 시 지 를 남 겨 주세요.편집장 은 제때에 답 해 드 리 겠 습 니 다.여기 서도 저희 사이트 에 대한 여러분 의 지지 에 감 사 드 립 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Kotlin의 기초 - 2부지난 글에서는 Kotlin이 무엇인지, Kotlin의 특징, Kotlin에서 변수 및 데이터 유형을 선언하는 방법과 같은 Kotlin의 기본 개념에 대해 배웠습니다. 유형 변환은 데이터 변수의 한 유형을 다른 데이터...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.