2016-11-27 5 views
0

アンドロイドスタジオランタイム中のボタンスイッチ

私は3つのボタンがあります。 1つのボタンを数秒間アクティブにし、他の2つを非アクティブにしてから、ランダムボタンを数秒間アクティブにします。スイッチ時間は徐々に減少するはずです。プロセス全体は2分間です。

アクティブなボタンには特定の色が必要です。

私はロジックを取得していないようです。私はこれのためのコードを取得すれば私は幸せになるでしょう。

私は基本レイアウトを持っています! MainActivityはデフォルトです!おかげさまで

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/activity_main" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="com.example.android.courtcounter.MainActivity"> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Hello World!" 
    android:layout_marginTop="36dp" 
    android:id="@+id/Score" 
    tools:text="0" 
    android:minHeight="52dp" 
    android:minWidth="52dp" 
    android:textSize="36sp" 
    tools:textStyle="bold" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    tools:textAlignment="center" /> 

<Button 
    android:text="3 Point" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="110dp" 
    android:id="@+id/button" 
    android:layout_below="@+id/textView" 
    android:layout_centerHorizontal="true" 
    android:elevation="14dp" 
    android:background="#ff0000"/> 

<Button 
    android:text="2 Point" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/button2" 
    android:layout_below="@+id/button" 
    android:layout_alignLeft="@+id/button" 
    android:layout_alignStart="@+id/button" 
    android:layout_marginTop="32dp" /> 

<Button 
    android:text="Free Throw" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="27dp" 
    android:id="@+id/button3" 
    android:layout_below="@+id/button2" 
    android:layout_centerHorizontal="true" /> 
</RelativeLayout> 

答えて

0

まず、ボタンの可視性を切り替えるために、あなたはsetVisibility(View.Visible)とsetVisibility(View.GONE)によってオン・オフボタンをオンに独自の「可視性マネージャ」を、記述する必要があります。データバインディングは、独自のロジックを記述する必要がないため、これを行うためのより良い方法です。 第2に、タイミングインターバル使用のために、rxJavaライブラリには、シーブルイベント(Observable.timer(..))と反復イベント(Observable.interval())を生成するメソッドがあります。 これらのイベントはバックグラウンドスレッドで実行されるため、最終的に.observeOn(AndroidSChedulers.mainThread())を使用します。 Handler.postDelayed()メソッドを使用してホイールを作成するのではなく、はるかに簡単になるので、このライブラリを使用する必要があります。 あなたの説明から、定期的なイベント、例えば毎秒を生成し、全体の時間の合計を生成する必要があります。その時間がある閾値を超えると、あなたは何らかの処置を行います。

関連する問題