2010-12-28 3 views
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로 동일한 질문 레이아웃을 두어야합니까? 그것은 나에게 불필요한 것처럼 보입니다. 또는 에만 액세스 할 수있는 또 다른 방법이 있습니까 질문 & 두 번째보기에서 대답하나요?
또는이를 수행하는 더 쉬운 방법이 있습니까?

감사합니다.

답변

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); 

이 방법이 올바른 방법일까요?

관련 문제