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 참조하는 이미지뷰만 제거하면요. 감사합니다.