0

我正在做一个练习一组多项选择题的培训应用程序。我想在两个问题之间做一个幻灯片动画 - 当用户正确回答一个问题时,它会滑到左边,而新的问题会从右边滑入。

目前,我的问题/答案布局如下所示(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>

在回答完问题并评估答案后,我只是更改了问题的文字和三个答案。很简单。

现在,我尝试使用 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 才能做到这一点?这对我来说似乎是多余的。还是有另一种方法可以访问第二个视图中的问题和答案?
或者有没有更简单的方法来实现这一点?

谢谢!

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 回答