0

我在製作測驗應用程序。爲了顯示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的S還重新定位自己。我正在提供我想做什麼的圖片描述。

假設,這是第一個問題在佈局:

Layout during first question

如果用戶選擇正確的選項,接下來的問題上來了,重新定位這樣佈局:

Layout during the second question

我不能達到這種佈局重新定位。我該怎麼做才能完成使命?

在此先感謝!

回答

1

我認爲你可以嘗試setVisibility(View.GONE)並膨脹你的新佈局風格!

另一個解決方法是創建具有所需按鈕位置的LayoutParams對象並將其應用於RadioGroup或ButtonGroup!

+0

我不知道這些,你能建議我一個教程嗎? – kittu88

0

爲這種行爲設置2個佈局將是一個優勢。但是,如果這不適合你,我會建議考慮將所有TextView放入一個RelativeLayout中,然後更新它們的相對位置以及它們各自的邊距。

+0

你如何建議這樣做。我不知道該怎麼辦 – kittu88

+0

如果可能,那麼你也可以建議我一些代碼編輯 – kittu88

相關問題