安卓数字时钟和表状时针

弄了一下午,就弄出来一个时针的转换,毕竟新手。。。。

package com.example.digitalclock;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.AnalogClock;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {
    private Button analogbutton;
    private TextView analogtextview;
    private AnalogClock analogclock;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		analogbutton=(Button)findViewById(R.id.analogclockbutton);
		
		analogtextview=(TextView)findViewById(R.id.analogClockTextView);
		
		analogclock=(AnalogClock)findViewById(R.id.analogClock);
		
		analogtextview.setText("Current clock is AnalogClock");
		
		analogbutton.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v){
			Intent myintent = new Intent();
			
			myintent.setClass(MainActivity.this,SupplActivity.class);
			
			MainActivity.this.startActivity(myintent);
			MainActivity.this.finish();
			}
		});
}
}

另一个类:

package com.example.digitalclock;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.DigitalClock;
import android.widget.TextView;

public class SupplActivity extends Activity {
    private Button digitalbutton;
    private TextView digitaltextview;
    private DigitalClock digitalclock;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_suppl);
		
		digitalbutton=(Button) findViewById(R.id.digitalClockButton);
		digitaltextview=(TextView) findViewById(R.id.digitalClockTextView);
		digitalclock = (DigitalClock) findViewById(R.id.digitalClock);
		
		digitaltextview.setText("Current clock is DigitalClock");
		
		digitalclock.setTextColor(Color.GREEN);
		digitalbutton.setOnClickListener(new View.OnClickListener() {
			@Override
          			public void onClick(View v) {
			   	// TODO Auto-generated method stub
				   Intent myintent = new Intent();
				   myintent.setClass(SupplActivity.this,MainActivity.class);
				   SupplActivity.this.startActivity(myintent);
				   SupplActivity.this.finish();
			}
		});
	}


}

貌似现在DigitalClock已经过时了,不过还是自己花一下午整出来的。

下边的是一个简单的布局:


    

数字时针的布局:


     

不过在这里边遇到一个问题,就是在布局中改变button的位置,就会报错,实在是找不到错误,如果哪位大神知道解决方法,望告知。。。。

你可能感兴趣的:(Android)