안드로이드 개발 정보
(글 수 1,067)
7시간 넘게 삽질하다가 이렇게 올리 게 되네요. 다들 아실꺼 같지만 ㅠㅠ
animation을 모르고 그냥 inflate로 받아서 혹시 될까 하다가 겨우 성공 ㅠㅠ
여기에서 도움을 많이 받아서 혹시라도 모르시는 분이 있을까봐 이렇게 올립니다 ^^;;;
더 깔끔한 방법은 없을까요?
몰라서 너무 더럽게 된거 같네요 혹시 좋은 방법 있으시면 가르쳐주세요 ㅠㅠ
main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" > <FrameLayout android:id="@+id/FrameLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="right" > <Button android:id="@+id/slide_out_btn" android:text="Slide Out" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Button android:id="@+id/slide_in_btn" android:text="Slide In" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/txtView1" android:text="txtView1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/txtView2" android:text="txtView2" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/txtView3" android:text="txtView3" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> <LinearLayout android:id="@+id/LinearLayout1" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="fill_parent" > <Button android:text="Camera" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Button android:text="Map" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> </FrameLayout> </LinearLayout>
slide_in
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="1.0" android:toAlpha="0" android:duration="300" /> <translate android:fromXDelta="0" android:toXDelta="-100%" android:duration="300" /> </set>
slide_out.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <alpha android:fromAlpha="0" android:toAlpha="1.0" android:duration="300" /> <translate android:fromXDelta="-100%p" android:toXDelta="0" android:duration="300" /> </set>
SpringMemoEntry.java
public class SpringMemoEntry extends Activity implements OnGestureListener { private GestureDetector mGestureDetector; private Button slideInBtn; private Button slideOutBtn; private TextView txtView1; private TextView txtView2; private TextView txtView3; private Animation slideIn, slideOut; private LinearLayout ll; private boolean isDrawingMenu = false; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ll = (LinearLayout)findViewById(R.id.LinearLayout1); txtView1 = (TextView)findViewById(R.id.txtView1); txtView2 = (TextView)findViewById(R.id.txtView2); txtView3 = (TextView)findViewById(R.id.txtView3); slideInBtn = (Button)findViewById(R.id.slide_in_btn); slideOutBtn = (Button)findViewById(R.id.slide_out_btn); slideOut = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_out); slideIn = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_in); slideOut.setAnimationListener(new AnimationListener() { public void onAnimationStart(Animation animation) { isDrawingMenu = true; } public void onAnimationRepeat(Animation animation) { } public void onAnimationEnd(Animation animation) { ll.setVisibility(View.VISIBLE); } }); slideIn.setAnimationListener(new AnimationListener() { public void onAnimationStart(Animation animation) { isDrawingMenu = true; } public void onAnimationRepeat(Animation animation) { } public void onAnimationEnd(Animation animation) { ll.setVisibility(View.INVISIBLE); } }); slideInBtn.setOnClickListener(new OnClickListener() { public void onClick(View v) { ll.startAnimation(slideIn); } }); slideOutBtn.setOnClickListener(new OnClickListener() { public void onClick(View v) { ll.startAnimation(slideOut); } }); mGestureDetector = new GestureDetector(this); } public boolean onTouchEvent(MotionEvent event) { if(MotionEvent.ACTION_UP == event.getAction()) isDrawingMenu = false; return mGestureDetector.onTouchEvent(event); } public boolean onDown(MotionEvent e) { return false; } public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return false; } public void onLongPress(MotionEvent e) { } public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { if( (e1.getX() - e2.getX()) > 0 ) { if(!isDrawingMenu && (ll.getVisibility() == View.VISIBLE )) ll.startAnimation(slideIn); } else if(!isDrawingMenu && (ll.getVisibility() == View.INVISIBLE)) ll.startAnimation(slideOut); txtView1.setText(Boolean.toString(isDrawingMenu)); txtView2.setText(Float.toString(e1.getX())); txtView3.setText(Float.toString(e2.getX())); return false; } public void onShowPress(MotionEvent e) { } public boolean onSingleTapUp(MotionEvent e) { return false; } }
좋은자료 감사합니다 ^^