我正在创建一个由here下载的模拟量表组成的应用程序。当我点击按钮时,针将偏转到该值。但在我的应用程序中,当我启动应用程序针时消失了。当我点击按钮然后针出现并开始偏转,我想在应用程序的开始出现针 这是我的java代码:
/*******************************************************************************
* Copyright (c) 2012 Evelina Vrabie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*******************************************************************************/
package org.codeandmagic.android.gauge.demo;
import java.util.Random;
import org.codeandmagic.android.gauge.GaugeView;
import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
private GaugeView mGaugeView1;
Button check;
private final Random RAND = new Random();
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mGaugeView1 = (GaugeView) findViewById(R.id.gauge_view1);
check = (Button)findViewById(R.id.button1);
check.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mTimer.start();
}
});
}
public final CountDownTimer mTimer = new CountDownTimer(30000, 1000) {
@Override
public void onTick(final long millisUntilFinished) {
mGaugeView1.setTargetValue((float)25.0);
//mGaugeView2.setTargetValue(RAND.nextInt(101));
}
@Override
public void onFinish() {}
};
}
这是我的XML代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gauge="http://schemas.android.com/apk/res/org.codeandmagic.android.gauge.demo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:gravity="center"
android:orientation="vertical"
android:padding="20dp" >
<org.codeandmagic.android.gauge.GaugeView
android:id="@+id/gauge_view1"
android:layout_width="match_parent"
android:layout_height="303dp"
android:layout_gravity="center" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Check" />
</LinearLayout>
答案 0 :(得分:0)
要在应用程序开始时显示针...在onCreate()方法调用
中mGaugeView1.setTargetValue(0);
初始化mGaugeView1后。