クイズアプリを作っています。MCQの質問を表示するために、次のレイアウトを使用しました。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/vg">
<TextView
android:id="@+id/question_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="41dp"
android:text="Question"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/option1_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="62dp"
android:layout_toLeftOf="@+id/question_textView"
android:text="Option 1"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/option2_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/option1_textView"
android:layout_alignBottom="@+id/option1_textView"
android:layout_marginLeft="48dp"
android:layout_toRightOf="@+id/question_textView"
android:text="Option 2"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/option4_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/option2_textView"
android:layout_alignParentBottom="true"
android:layout_marginBottom="22dp"
android:text="Option 4"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/option3_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/option4_textView"
android:layout_alignBottom="@+id/option4_textView"
android:layout_alignLeft="@+id/option1_textView"
android:text="Option 3"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
XMLを解析して、質問、オプション、および正解を取得しています。ユーザーが特定の質問に対して正しいオプションを選択すると、TextViewは次の質問とそれぞれのオプションで更新されます。これは私がそれをしている方法です:
NodeList nl = doc.getElementsByTagName(KEY_MCHOICE);
// looping through all item nodes <item>
for ( i = 0; i < nl.getLength();i++) {
loop_checker=i;
// while(counter< nl.getLength())
// {
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(count_questions);
// adding each child node to HashMap key => value
map.put(KEY_MCHOICE, parser.getValue(e, KEY_MCHOICE));
map.put(KEY_ID, parser.getValue(e, KEY_ID));
map.put(KEY_QUESTION, parser.getValue(e, KEY_QUESTION));
question_view.setText(parser.getValue(e, KEY_QUESTION));
map.put(KEY_OPTION1, parser.getValue(e, KEY_OPTION1));
//option1_str =parser.getValue(e, KEY_OPTION1);
option1.setText(parser.getValue(e, KEY_OPTION1));
map.put(KEY_OPTION2, parser.getValue(e, KEY_OPTION2));
option2.setText(parser.getValue(e, KEY_OPTION2));
//option2_str =parser.getValue(e, KEY_OPTION2);
map.put(KEY_OPTION3, parser.getValue(e, KEY_OPTION3));
option3.setText(parser.getValue(e, KEY_OPTION3));
//option3_str =parser.getValue(e, KEY_OPTION3);
map.put(KEY_OPTION4, parser.getValue(e, KEY_OPTION4));
option4.setText(parser.getValue(e, KEY_OPTION4));
//option4_str =parser.getValue(e, KEY_OPTION4);
map.put(KEY_ANSWER, parser.getValue(e, KEY_ANSWER));
// makeAToast(parser.getValue(e, KEY_ANSWER));
answer_str =parser.getValue(e, KEY_ANSWER);
// adding HashList to ArrayList
menuItems.add(map);
}
さて、私がやりたいのは、ユーザーが特定の質問に正しい答えを出し、質問が変更され、TextViewも自分自身を再配置したときです。私がやりたいことの絵による説明を提供しています。
これが最初の質問のレイアウトだとします。
ユーザーが正しいオプションを選択すると、次の質問が表示され、次のようにレイアウトが再配置されます。
このレイアウトの再配置を実現できません。ミッションを達成するにはどうすればよいですか?
前もって感謝します!