마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

슬라이드메뉴를 구현했는데 EditText관련 문제! 해결해주세요ㅜㅜ

0 추천
package com.example.slidemenuex;

import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Context;

import android.support.v4.app.FragmentActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.TranslateAnimation;
import android.widget.EditText;

public class MainActivity extends FragmentActivity implements AnimationListener {

	View menu;
	View menu2;
	View app;

	EditText edit;

	boolean menuOut = false;
	AnimParams animParams = new AnimParams();

	class ClickListener implements OnClickListener {

		public void onClick(View v) {
			Animation anim = null;
			int w = app.getMeasuredWidth();
			int h = app.getMeasuredHeight();
			int left = (int) (app.getMeasuredWidth() * 0.8);

			switch (v.getId()) {
			case R.id.btn1:
				if (!menuOut) {
					anim = new TranslateAnimation(0, left, 0, 0);
					menu.setVisibility(View.VISIBLE);
					menu2.setVisibility(View.INVISIBLE);
					animParams.init(left, 0, left + w, h);

				} else {
					anim = new TranslateAnimation(0, -left, 0, 0);
					animParams.init(0, 0, w, h);
				}
				break;
			case R.id.btn2:
				if (!menuOut) {
					anim = new TranslateAnimation(0, -left, 0, 0);
					menu.setVisibility(View.INVISIBLE);
					menu2.setVisibility(View.VISIBLE);
					animParams.init(-left, 0, -left + w, h);
				} else {
					animParams.init(0, 0, w, h);
					anim = new TranslateAnimation(0, left, 0, 0);
				}
				break;

			}

			anim.setDuration(500);
			anim.setAnimationListener(MainActivity.this);
			anim.setFillAfter(true);
			app.startAnimation(anim);
		}
	}

	@SuppressLint("NewApi")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_main);

		menu = findViewById(R.id.menu);
		menu2 = findViewById(R.id.menu2);
		edit = (EditText) findViewById(R.id.ev);

		app = findViewById(R.id.main);
		app.findViewById(R.id.btn1).setOnClickListener(new ClickListener());
		app.findViewById(R.id.btn2).setOnClickListener(new ClickListener());

	}

	void layoutApp(boolean menuOut) {
		app.layout(animParams.left, animParams.top, animParams.right,
				animParams.bottom);
		app.clearAnimation();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public void onAnimationEnd(Animation arg0) {
		// TODO Auto-generated method stub

		menuOut = !menuOut;
		if (!menuOut) {
			menu.setVisibility(View.INVISIBLE);
			menu2.setVisibility(View.INVISIBLE);
		}
		layoutApp(menuOut);
	}

	@Override
	public void onAnimationRepeat(Animation arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onAnimationStart(Animation arg0) {
		// TODO Auto-generated method stub

	}

	static class AnimParams {
		int left, right, top, bottom;

		void init(int left, int top, int right, int bottom) {
			this.left = left;
			this.top = top;
			this.right = right;
			this.bottom = bottom;
		}
	}

}
<FrameLayout 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=".MainActivity" >

    <LinearLayout
        android:id="@+id/menu"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ffe8d9ff"
        android:orientation="vertical" >
        
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_launcher" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="홍길동\n닉네임" />
        </LinearLayout>
      
    </LinearLayout>

    <LinearLayout
        android:id="@+id/menu2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#fff6f6f6"
        android:orientation="vertical"
        android:paddingLeft="80dip"
        android:paddingRight="20dip" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:orientation="horizontal" >

            <EditText
                android:id="@+id/ev"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1" />

            <ImageView
                android:layout_width="20dip"
                android:layout_height="20dip"
                android:layout_gravity="bottom"
                android:src="@drawable/searching" />
        </LinearLayout>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ffffd9fa"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/btn1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Menu"
                android:textSize="15sp" />

            <TextView
                android:id="@+id/tv"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:text="Title"
                android:textSize="15sp" />

            <Button
                android:id="@+id/btn2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Search"
                android:textSize="15sp" />
        </LinearLayout>
    </LinearLayout>

</FrameLayout>

 

처음으로 질문드려요.

구글검색에서 슬라이드메뉴 예제소스를 얻어서 조금 수정했습니다.

페이스북을 보면 슬라이드메뉴 안에 검색부분 있잖아요.

그래서 슬라이드메뉴 안에 EditText를 넣었는데,

EditText에 텍스트를 입력하면 화면이 처음 화면으로 돌아갑니다. 

포커스는 계속 EditText에 있구요.

 

FrameLayout 순서를 바꿔서 해보기도 했는데 안돼네요.

제 생각에는 텍스트 입력 시 invalidate되서 화면 전체가 처음상테로 돌아가는 것 같은데..맞나요?

슬라이드메뉴안에서 프레그먼트 교체시에도 같은 현상이 일어나더라구요.

 

아시는 분은 꼭 해결 부탁드립니다 ㅜㅜ

EditText에 입력해도 화면상태가 유지되도록이요...

위 소스 그대로 돌려보실수있어요. @drawable/searching 참조하는 이미지뷰만 제거하면요. 감사합니다.

아임성민 (120 포인트) 님이 2013년 6월 25일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...