0

一連の多肢選択問題を練習するトレーニング アプリケーションを実行しています。2 つの質問の間でスライド アニメーションを実行したいと思います。ユーザーが 1 つの質問に正しく答えると、左にスライドし、新しい質問が右からスライドします。

現在、私の質問/回答のレイアウトは次のようになっています (question.xml):

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
        <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:gravity="center"
        >
                <TextView
                        android:id="@+id/question" 
                    android:layout_width="fill_parent"  
                    android:layout_height="wrap_content" 
                    android:textColor="#000000"
                    android:textSize="8pt"
                    android:textStyle="bold"
                android:layout_margin="5px"
                    android:layout_marginBottom="10dp"
                    android:clickable="true"
                    />
                <RadioGroup android:id="@+id/answers"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical"
                        android:layout_margin="5px"
                        >
                        <RadioButton android:id="@+id/answer_a"
                                android:layout_width="fill_parent"
                                android:layout_height="wrap_content"
                                android:textColor="#000000"
                                android:textSize="7pt"
                                android:layout_margin="5dp"
                                android:layout_marginBottom="10dp"
                                />
                        <RadioButton android:id="@+id/answer_b"
                                android:layout_width="fill_parent"
                                android:layout_height="wrap_content"
                                android:textColor="#000000"
                                android:textSize="7pt"
                                android:layout_margin="5dp"
                                android:layout_marginBottom="10dp"
                                />
                        <RadioButton android:id="@+id/answer_c"
                                android:layout_width="fill_parent"
                                android:layout_height="wrap_content"
                                android:textColor="#000000"
                                android:textSize="7pt"
                                android:layout_margin="5dp"
                                android:layout_marginBottom="10dp"
                                />
            </RadioGroup>
        </LinearLayout>
</ScrollView>

質問に回答し、回答を評価した後、質問のテキストと 3 つの回答を変更しました。かなり簡単です。

ここで、ViewFlipper を使用してアニメーションを実行してみました。

<ViewFlipper android:id="@+id/flipper"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <include android:id="@+id/current_view" layout="@layout/question" />
    <include android:id="@+id/next_view"    layout="@layout/question" />
</ViewFlipper>

しかし、その方法では、現在の質問と次の質問のビューに個別にアクセスできませんfindViewById

これを行うには、ID が異なるだけで 2 つの同じ質問レイアウトが必要ですか? 私には冗長に思えます。または、2 番目のビューで質問と回答のみにアクセスする別の方法はありますか?
または、これを達成するためのより簡単な方法はありますか?

ありがとう!

4

1 に答える 1

0

わかりました、最後にこれを行いました-questions.xml新しい質問を準備するたびにレイアウトを膨らませ、それをフリッパーに追加して反転させます。また、フリッパーが大きくなりたくないので、以前の古いフリップが複数ある場合は削除します (基本的に最初以外は常に)。

    LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.question, null);

    txtPracticeQuestion = (TextView)    layout.findViewById(R.id.question);
    rgrpPracticeAnswers = (RadioGroup)  layout.findViewById(R.id.answers);
    rbtnPracticeAnswerA = (RadioButton) layout.findViewById(R.id.answer_a);
    rbtnPracticeAnswerB = (RadioButton) layout.findViewById(R.id.answer_b);
    rbtnPracticeAnswerC = (RadioButton) layout.findViewById(R.id.answer_c);

    rbtnPracticeAnswerA.setOnClickListener(this);
    rbtnPracticeAnswerB.setOnClickListener(this);
    rbtnPracticeAnswerC.setOnClickListener(this);

    txtPracticeQuestion.setText(currentQuestion.get("question").toString());
    rbtnPracticeAnswerA.setText(currentQuestion.get("answer_a").toString());
    rbtnPracticeAnswerB.setText(currentQuestion.get("answer_b").toString());
    rbtnPracticeAnswerC.setText(currentQuestion.get("answer_c").toString());

    if (flipper.getChildCount() > 1)
        flipper.removeViewAt(0);

    flipper.addView(layout);

これは正しいアプローチでしょうか?

于 2010-12-28T20:53:45.880 に答える