2013-04-26 2 views
0

시계를 표시하는 앱을 만들고 있는데, 사용자가 화면을 터치 할 때마다 colors.xml 파일에서 미리 선택된 색상 목록). 그러나 어디서부터 시작해야하는지 알지 못했습니다. 누군가 올바른 방향으로 나를 가리킬 수 있습니까?touch (digitalClock) touch on touch (screen)

가 여기에 주요 활동입니다 :

public class MainActivity extends Activity { 
private static final Random RANDOM = new Random(); 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 
    setContentView(R.layout.activity_main); 

    Handler handler = new RandomMoveHandler((TextView) findViewById(R.id.digitalClock1)); 
    handler.sendEmptyMessage(0); 
} 

// Make the handler subclass static because of this: http://stackoverflow.com/a/11408340/111777 
private static class RandomMoveHandler extends Handler { 
    private final WeakReference<TextView> textViewWeakReference; 

    private RandomMoveHandler(TextView textView) { 
     this.textViewWeakReference = new WeakReference<TextView>(textView); 
    } 

    @Override 
    public void handleMessage(Message msg) { 
     TextView textView = textViewWeakReference.get(); 
     if (textView == null) { 
      Log.i(TAG, "WeakReference is gone so giving up."); 
      return; 
     } 

     int x = RANDOM.nextInt(350 - 100); 
     int y = RANDOM.nextInt(800 - 100); 

     Log.i(TAG, String.format("Moving text view to (%d, %d)", x, y)); 
     textView.setX(x); 
     textView.setY(y); 

     //change the text position here 
     this.sendEmptyMessageDelayed(0, 30000); 
    } 
} 

private static final String TAG = MainActivity.class.getSimpleName(); 

}

여기 레이아웃 XML입니다 :

<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
tools:context=".MainActivity" 
android:background="@color/black" > 

<DigitalClock 
    android:id="@+id/digitalClock1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="DigitalClock" 
    android:textColor="@color/ics_blue" 
    android:textSize="28sp" /> 

답변

0

내가 DigitalClock와 거래를하지 않은하지만 난 생각, 먼저 DigitalClock 변수, n을 참조해야합니다. o TextView. 그리고 두 번째로 터치 이벤트를 가로 채기 위해 액티비티의 onTouckEvent 메서드를 재정의해야 할 때마다 사용자가 화면에 닿을 때마다 콜백합니다.

0

당신은 TimerTask를가 to.continusly이 view.setOnTouchListener

    처럼 그 시계보기에

을 touchlistener 구현 시간

  • 을 보여 다음 단계

    1. 사용을 따라야한다
    2. 배열 만들기이 색상은 다음과 같습니다.

    int [] colr = {Color.BLACK, Color.BLUE};

    터치 이벤트에서 임의의 색인을 사용하여보기의 색으로 설정하십시오.