2014-10-08 4 views
0

내 앱에서 동일한 활동 인 RelativeLayout에서 애니메이션을 수행하고 다른 RelativeLayout이 표시됩니다. 나타나는 레이아웃에는 버튼이 클릭되지 않고 다음 페이지로 이동하려고 할 때 버튼이 포함됩니다. 따라서 응용 프로그램이 중단됩니다.버튼이 클릭되지 않습니다.

MainActivity.java

public class P3 extends Activity { 
    RelativeLayout rel, rel1, rel2, rel4; 
    Animation slide_down, slide_center, slide_up, slide_top; 
    AnimationDrawable frameAnimation; 
    ViewFlipper flippy; 
    int i; 
    Button b; 
    private Context context; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.p3); 
     int currentOrientation = getResources().getConfiguration().orientation; 
     rel1 = (RelativeLayout) findViewById(R.id.Rel_lay_1_p3); 
     if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) { 
      context = this; 
      LayoutInflater inflater = LayoutInflater.from(context); 
      View view = inflater.inflate(R.layout.lay_inflate_land, null); 
      rel1.addView(view); 
     } else { 
      context = this; 
      LayoutInflater inflater = LayoutInflater.from(context); 
      View view = inflater.inflate(R.layout.lay_inflate, null); 
      rel1.addView(view); 
     } 

     new Handler().postDelayed(new Runnable() { 
      @Override 
      public void run() { 
       context = getApplicationContext(); 
       int currentOrientation = getResources().getConfiguration().orientation; 
       if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) { 
        LayoutInflater inflater = LayoutInflater.from(context); 
        View view = inflater.inflate(
          R.layout.green_lay_inflate_land, null); 
        rel1.addView(view); 

       } else { 
        context = getApplicationContext(); 
        LayoutInflater inflater = LayoutInflater.from(context); 
        View view = inflater.inflate(R.layout.green_lay_inflate, 
          null); 
        rel1.addView(view); 
       } 
      } 
     }, 500); 

     new Handler().postDelayed(new Runnable() { 

      @Override 
      public void run() { 
       int currentOrientation = getResources().getConfiguration().orientation; 
       if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) { 
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 
        i = 1; 
       } else { 
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
        i = 2; 
       } 
       rel = (RelativeLayout) findViewById(R.id.Rel_lay_1_p3_n); 
       slide_down = AnimationUtils.loadAnimation(
         getApplicationContext(), R.anim.go_down); 
       rel.startAnimation(slide_down); 

       slide_center = AnimationUtils.loadAnimation(
         getApplicationContext(), R.anim.go_down); 
       slide_center.setAnimationListener(animationListener); 
       rel1.startAnimation(slide_center); 
      } 
     }, 1000); 

    } 

    private AnimationListener animationListener = new AnimationListener() { 

     @Override 
     public void onAnimationStart(Animation animation) { 

     } 

     @Override 
     public void onAnimationRepeat(Animation animation) { 

     } 

     @Override 
     public void onAnimationEnd(Animation animation) { 

      rel2 = (RelativeLayout) findViewById(R.id.Rel_lay_2_p3); 

      rel4 = (RelativeLayout) findViewById(R.id.Rel_lay_2_1_p3); 
      rel4.setVisibility(View.INVISIBLE); 
      if (i == 1) { 
       LayoutInflater inflater = LayoutInflater.from(context); 
       View view = inflater.inflate(R.layout.green_lay_inflate_land, 
         null); 

       rel2.addView(view); 
       rel.setVisibility(View.INVISIBLE); 
       rel2.setVisibility(View.VISIBLE); 

       inflater = LayoutInflater.from(context); 
       view = inflater.inflate(R.layout.lay_inflate_land, null); 

       rel4.addView(view); 
      } else { 
       LayoutInflater inflater = LayoutInflater.from(context); 
       View view = inflater.inflate(R.layout.green_lay_inflate, null); 

       rel2.addView(view); 
       rel.setVisibility(View.INVISIBLE); 
       rel2.setVisibility(View.VISIBLE); 

       inflater = LayoutInflater.from(context); 
       view = inflater.inflate(R.layout.lay_inflate, null); 

       rel4.addView(view); 
      } 
      flippy = (ViewFlipper) findViewById(R.id.viewFlipper1); 
      flippy.setFlipInterval(500); 
      flippy.startFlipping(); 
      new Handler().postDelayed(new Runnable() { 

       @Override 
       public void run() { 
        flippy.stopFlipping(); 

       } 
      }, 5000); 

      new Handler().postDelayed(new Runnable() { 

       @Override 
       public void run() { 

        rel2.setVisibility(View.VISIBLE); 
        rel4.setVisibility(View.INVISIBLE); 

        if (i == 1) { 
         LayoutInflater inflater = LayoutInflater.from(context); 
         View view = inflater.inflate(
           R.layout.green_lay_inflate_land, null); 

         rel2.addView(view); 

        } else { 
         context = getApplicationContext(); 
         LayoutInflater inflater = LayoutInflater.from(context); 
         View view = inflater.inflate(
           R.layout.green_lay_inflate, null); 
         rel2.addView(view); 
        } 
        rel = (RelativeLayout) findViewById(R.id.Rel_lay_2_p3_n); 
        rel.setVisibility(View.VISIBLE); 
        slide_up = AnimationUtils.loadAnimation(
          getApplicationContext(), R.anim.go_up); 

        rel2.setVisibility(View.VISIBLE); 

        slide_top = AnimationUtils.loadAnimation(
          getApplicationContext(), R.anim.go_up); 
        slide_top.setAnimationListener(animationListener_come_up); 
        rel1.setVisibility(View.VISIBLE); 
        rel2.setVisibility(View.INVISIBLE); 
        rel.startAnimation(slide_up); 
        rel1.startAnimation(slide_up); 
        if (i == 1) { 
         LayoutInflater inflater = LayoutInflater.from(context); 
         View view = inflater.inflate(
           R.layout.green_lay_inflate_land, null); 

         rel2.addView(view); 

        } else { 
         context = getApplicationContext(); 
         LayoutInflater inflater = LayoutInflater.from(context); 
         View view = inflater.inflate(
           R.layout.green_lay_inflate, null); 
         rel2.addView(view); 
        } 
       } 

      }, 5100); 

     } 
    }; 

    private AnimationListener animationListener_come_up = new AnimationListener() { 

     @Override 
     public void onAnimationStart(Animation animation) { 

     } 

     @Override 
     public void onAnimationRepeat(Animation animation) { 

     } 

     @Override 
     public void onAnimationEnd(Animation animation) { 



      b = (Button) findViewById(R.id.b_conti_p3); 
      b.setOnClickListener(new OnClickListener() { 

       @Override 
       public void onClick(View v) { 
        Intent nextPageIntent = new Intent(getApplicationContext(), 
          P6.class); 
        startActivity(nextPageIntent); 

       } 
      }); 

     } 
    }; 
} 

MainActivity.xml

<ScrollView 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" 
    tools:context="com.pal1.ui.P3" 
    tools:ignore="MergeRootFrame" 
    android:id="@+id/container2" 
     android:background="#E5E4E2"> 

    <RelativeLayout 
     android:id="@+id/Rel_lay_p3" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#ffffff" > 

     <TextView 
      android:id="@+id/t_set_conn_p3_n" 
      style="@dimen/activity_horizontal_margin" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:background="#4cc417" 
      android:gravity="center" 
      android:minHeight="30dp" 
      android:text="@string/set_conn" 
      android:textColor="@android:color/white" 
      android:textSize="15sp" 
      android:textStyle="bold" /> 

     <!-- Top Image --> 

     <RelativeLayout 
      android:id="@+id/Rel_lay_1_p3" 
      android:layout_width="match_parent" 
      android:layout_height="150dp" 
      android:layout_below="@+id/t_set_conn_p3_n" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentRight="true" 
      android:adjustViewBounds="true" 
      android:background="#ffffff" > 
     </RelativeLayout> 

     <!-- Center Image --> 

     <ViewFlipper 
      android:id="@+id/viewFlipper1" 
      android:layout_width="match_parent" 
      android:layout_height="150dp" 
      android:layout_alignParentRight="true" 
      android:layout_centerVertical="true" 
      android:layout_marginTop="52dp" 
      android:background="#ffffff" > 

      <RelativeLayout 
       android:id="@+id/Rel_lay_2_p3" 
       android:layout_width="match_parent" 
       android:layout_height="150dp" 
       android:background="#ffffff" 
       android:visibility="gone" 
       /> 

      <RelativeLayout 
       android:id="@+id/Rel_lay_2_1_p3" 
       android:layout_width="match_parent" 
       android:layout_height="150dp" 
       android:background="#ffffff" 
       android:visibility="gone" /> 
     </ViewFlipper> 

     <!-- Actual layout --> 

     <RelativeLayout 
      android:id="@+id/Rel_lay_1_p3_n" 
      android:layout_width="match_parent" 
      android:layout_height="360dp" 
      android:layout_alignParentBottom="true" 
      android:layout_below="@+id/Rel_lay_1_p3" 
      android:layout_alignParentLeft="true" 
      android:background="#E5E4E2" > 

      <TextView 
       android:id="@+id/t_1_p3_n" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="top" 
       android:gravity="top" 
       android:padding="5dp" 
       android:text="@string/Message_bold_p3" 
       android:textColor="#000000" 
       android:textSize="18sp" 
       android:textStyle="bold" /> 

      <TextView 
       android:id="@+id/t_2_p3_n" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/t_1_p3_n" 
       android:layout_margin="0dp" 
       android:gravity="top" 
       android:padding="10dp" 
       android:text="@string/Message_p3" 
       android:textColor="#565051" 
       android:textSize="15sp" /> 
     </RelativeLayout> 

     <!-- Invisible Layout --> 

     <RelativeLayout 
      android:id="@+id/Rel_lay_2_p3_n" 
      android:layout_width="match_parent" 
      android:layout_height="360dp" 
      android:layout_below="@+id/Rel_lay_1_p3" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentLeft="true" 
      android:background="#E5E4E2" 
      android:visibility="invisible" > 

      <TextView 
       android:id="@+id/t_1_p5_n" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="top" 
       android:gravity="top" 
       android:padding="5dp" 
       android:text="@string/Message_bold_p5" 
       android:textColor="#000000" 
       android:textSize="18sp" 
       android:textStyle="bold" /> 

      <Button 
       android:id="@+id/b_conti_p3" 
       android:layout_width="match_parent" 
       android:layout_height="50dp" 
       android:layout_alignParentBottom="true" 
       android:layout_centerHorizontal="true" 
       android:layout_marginLeft="15dp" 
       android:layout_marginRight="15dp" 
       android:layout_marginBottom="28dp" 
       android:background="@drawable/round_button" 
       android:ellipsize="none" 
       android:text="@string/Button_p5" 
       android:textColor="@android:color/white" 
       android:clickable="true" 
       android:textSize="15sp" 
       android:textStyle="bold" /> 

      <TextView 
       android:id="@+id/t_2_p5_n" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_marginLeft="15dp" 
       android:layout_marginRight="15dp" 

       android:layout_alignParentLeft="true" 
       android:layout_below="@+id/t_1_p5_n" 
       android:layout_margin="0dp" 
       android:gravity="top" 
       android:padding="10dp" 
       android:text="@string/Message_p5" 
       android:textColor="#565051" 
       android:textSize="15sp" /> 
     </RelativeLayout> 
    </RelativeLayout> 

</ScrollView> 
+0

유 버튼 이름 PLZ를 sepecify 수 있습니까? – KOTIOS

+0

버튼 하나만 있습니다. (b_conti_p3) xml 파일의 "보이지 않는 레이아웃"에 있습니다. –

+0

'앱이 멈 춥니 다 '라는 말은 앱이 충돌하거나 다른 것을 의미합니다. – kId

답변

2

종료 애니메이션 후 버튼 클릭 이벤트를 사용하는 이유는 무엇입니까? 애니메이션 종료 후 어떤 일을하고 있습니까? 귀하의 코드에 따라 그렇게 생각하지 않습니다. 그래서 OnCreate에서 사용하십시오. 더미 애니메이션과 레이아웃을 사용하여 테스트하고 테스트했습니다.

 setContentView(R.layout.main); 
     b = (Button) findViewById(R.id.b_conti_p3); 
     b.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       Intent nextPageIntent = new Intent(MainActivity.this, 
         NextActivity.class); 
       startActivity(nextPageIntent); 
       Toast.makeText(getApplicationContext(), "Hello", Toast.LENGTH_SHORT) 
       .show(); 

      } 

     }); 

enter image description here

enter image description here

관련 문제