在相同类型的视图之间制作动画的正确方法?
我正在做一个训练应用程序,练习一组多项选择题。我想在两个问题之间制作幻灯片动画 - 当用户正确回答一个问题时,它会滑向左侧,而新问题会从右侧滑入。
目前,我的问题/答案布局如下所示(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 不同)才能执行此操作?这对我来说似乎多余。或者是否有其他方法可以仅访问第二个视图中的问题和答案?
或者有更简单的方法来完成这个任务吗?
谢谢!
I'm doing a training application that practices a set of multiple-choice questions. I'd like to do a slide animation between two questions - when the user correctly answers one question, it slides away to the left while the new one slides in from right.
Currently, my question/answer layout looks like this (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>
After answering the question and evaluating the answer, I just changed the text of the question and the three answers. Pretty straightforward.
Now, I've tried using ViewFlipper to do the animations:
<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>
But that way I can't access the views in the current and next question separately via findViewById
.
Do I need to have two same question layouts just with different IDs to do this? it seems redundant to me. Or is there another way to access only the question&answers in the second view?
Or is there an easier way to accomplish this?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,最后我这样做了 - 每次准备一个新问题时,我都会膨胀
questions.xml
布局,将其添加到翻转器并翻转它。由于我不希望翻转器变得很大,因此如果有多个翻转器(基本上总是除了第一次),我会删除以前的旧翻转器。
这是正确的方法吗?
Ok, in the end I did this - I inflate the
questions.xml
layout every time I prepare a new question, add it to the flipper and flip it.And as I don't want the flipper to become huge, I delete the previous old flips if there's more than one (basically always except the first time).
Would this be the correct approach?