0

I m creating an clock which will show the present time on the UI I want to show the digitd through the pictures from 0 to 1 For this i m taking the images from 0 to 9 one over the another making a stack and then changing the tranparancy of the image according to the number i want to show

@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
super.onCreate(savedInstanceState);
i0.setAlpha(1);
i1.setAlpha(1);
i2.setAlpha(1);
i3.setAlpha(1);
i4.setAlpha(1);
i5.setAlpha(1);
i6.setAlpha(1);
i7.setAlpha(1);
i8.setAlpha(1);
i9.setAlpha(1);
Timer Tim=new Timer();
Tim.schedule(new TimerTask() 
{   @Override
    public void run() 
    {    runThread();   }
},1000,1000);

}


private void runThread()
{   runOnUiThread (new Thread(new Runnable() 
    {   public void run() 
        {   

        if(x==0){
            i0.setAlpha(1000);
            i1.setAlpha(1);
            i2.setAlpha(1);
            i3.setAlpha(1);
            i4.setAlpha(1);
            i5.setAlpha(1);
            i6.setAlpha(1);
            i7.setAlpha(1);
            i8.setAlpha(1);
            i9.setAlpha(1);}

        if(x==1){
            i0.setAlpha(1);
            i1.setAlpha(1000);
            i2.setAlpha(1);
            i3.setAlpha(1);
            i4.setAlpha(1);
            i5.setAlpha(1);
            i6.setAlpha(1);
            i7.setAlpha(1);
            i8.setAlpha(1);
            i9.setAlpha(1);}

        if(x==2){
            i0.setAlpha(1);
            i1.setAlpha(1);
            i2.setAlpha(1000);
            i3.setAlpha(1);
            i4.setAlpha(1);
            i5.setAlpha(1);
            i6.setAlpha(1);
            i7.setAlpha(1);
            i8.setAlpha(1);
            i9.setAlpha(1);}

        if(x==3){
            i0.setAlpha(1);
            i1.setAlpha(1);
            i2.setAlpha(1);
            i3.setAlpha(1000);
            i4.setAlpha(1);
            i5.setAlpha(1);
            i6.setAlpha(1);
            i7.setAlpha(1);
            i8.setAlpha(1);
            i9.setAlpha(1);}

        if(x==4){
            i0.setAlpha(1);
            i1.setAlpha(1);
            i2.setAlpha(1);
            i3.setAlpha(1);
            i4.setAlpha(1000);
            i5.setAlpha(1);
            i6.setAlpha(1);
            i7.setAlpha(1);
            i8.setAlpha(1);
            i9.setAlpha(1);}

        if(x==5){
            i0.setAlpha(1);
            i1.setAlpha(1);
            i2.setAlpha(1);
            i3.setAlpha(1);
            i4.setAlpha(1);
            i5.setAlpha(1000);
            i6.setAlpha(1);
            i7.setAlpha(1);
            i8.setAlpha(1);
            i9.setAlpha(1);}

        if(x==6){
            i0.setAlpha(1);
            i1.setAlpha(1);
            i2.setAlpha(1);
            i3.setAlpha(1);
            i4.setAlpha(1);
            i5.setAlpha(1);
            i6.setAlpha(1000);
            i7.setAlpha(1);
            i8.setAlpha(1);
            i9.setAlpha(1);}

        if(x==7){
            i0.setAlpha(1);
            i1.setAlpha(1);
            i2.setAlpha(1);
            i3.setAlpha(1);
            i4.setAlpha(1);
            i5.setAlpha(1);
            i6.setAlpha(1);
            i7.setAlpha(1000);
            i8.setAlpha(1);
            i9.setAlpha(1);}

        if(x==8){
            i0.setAlpha(1);
            i1.setAlpha(1);
            i2.setAlpha(1);
            i3.setAlpha(1);
            i4.setAlpha(1);
            i5.setAlpha(1);
            i6.setAlpha(1);
            i7.setAlpha(1);
            i8.setAlpha(1000);
            i9.setAlpha(1);}

        if(x==9){
            i0.setAlpha(1);
            i1.setAlpha(1);
            i2.setAlpha(1);
            i3.setAlpha(1);
            i4.setAlpha(1);
            i5.setAlpha(1);
            i6.setAlpha(1);
            i7.setAlpha(1);
            i8.setAlpha(1);
            i9.setAlpha(1000);}

        x=x+1;
        if (x==10){x=0;}
        }
    }));
}

}

I cannot take 10 images for each digit i want to show can any 1 suggest any other way to do that. Is it possible through "view"..? can any1 tel me how to use views in android..?

4

1 に答える 1

0

すべての画像ではなく、フォントを使用した場合、これは簡単になると思います。時間を入れた TextView を使用してから背景を変更することで、同じ効果を達成できると確信しています。

assets フォルダーからフォントを使用する方法については、http://www.youtube.com/watch?v=kOJGmVXuuFAを参照してください。

編集 (新しい回答): 時計の桁数に応じて、時計の xml レイアウトで ImageButtons を作成します。

    int[] x = {....} \\the digits you wish to display
    int[] images = { R.drawable.0, R.drawable.1,...,R.drawable.9); //the saves of your images 0-9
    int[] btnArray = { R.id.b1, R.id.b2,...}; //the ImageButtons used to display your digits
    for(int i = 0; i < numberofbuttons; i++) {
        ImageButton btn = (ImageButton) findViewById(btnArray[i-1]);
        btn.setBackgroundDrawable(getResources().getDrawable(
                images[x[i]])); 
    }
于 2013-02-02T15:51:39.620 に答える