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

안드로이드 프래그먼트 이동 시 프래그먼트가 겹치는 것 같습니다.

0 추천

안녕하세요. MainActivity에서 온클릭 이벤트 시에 지정한 레이아웃 프래그먼트로 replace를 시켰는데, 애니메이션을 적용했더니 기존 main 레이아웃에 프래그먼트 레이아웃이 덮어씌워집니다. 왜 이러는걸까요?

MainActivity 입니다

public class MenuActivity extends BaseActivity implements View.OnClickListener{
    ImageView imgPremium, imgSelf, imgLibrary, imgSay;
    LinearLayout menu_detail;
    TextView textPremium, textSelf, textLibrary, textSay;
    int mCurrentFragmentIndex;
    public final static int FRAGMENT_ONE = 0;
    public final static int FRAGMENT_TWO = 1;
    public final static int FRAGMENT_THREE = 2;
    public final static int FRAGMENT_FOUR = 3;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        imgPremium = (ImageView)findViewById(R.id.img_premium);
        imgPremium.setOnClickListener(this);
        imgSelf = (ImageView)findViewById(R.id.img_self);
        imgSelf.setOnClickListener(this);
        imgLibrary = (ImageView)findViewById(R.id.img_library);
        imgLibrary.setOnClickListener(this);
        imgSay = (ImageView)findViewById(R.id.img_say);
        imgSay.setOnClickListener(this);
        textPremium = (TextView)findViewById(R.id.txt_premium);
        textPremium.setOnClickListener(this);
        textSelf = (TextView)findViewById(R.id.txt_self);
        textSelf.setOnClickListener(this);
        textLibrary = (TextView)findViewById(R.id.txt_library);
        textLibrary.setOnClickListener(this);
        textSay = (TextView)findViewById(R.id.txt_say);
        textSay.setOnClickListener(this);
    }

    public void fragmentReplace(int reqNewFragmentIndex) {

        Fragment newFragment = null;


        newFragment = getFragment(reqNewFragmentIndex);

        // replace fragment
        final FragmentTransaction transaction = getSupportFragmentManager()
                .beginTransaction();
        transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
        transaction.replace(R.id.menu_frame_layout, newFragment);


        // Commit the transaction
        transaction.commit();


    }
    private Fragment getFragment(int idx) {
        Fragment newFragment = null;

        switch (idx) {
            case FRAGMENT_ONE:
                newFragment = new PremiumFragment();
                break;
            case FRAGMENT_TWO:
                newFragment = new SelfFragment();
                break;
            case FRAGMENT_THREE:
                newFragment = new LibraryFragment();
                break;

            case FRAGMENT_FOUR:
                newFragment = new SayFragment();
                break;
        }

        return newFragment;
    }



    public void onClick(View v) {
        Intent i;
        switch (v.getId()) {
            case R.id.img_premium:
            case R.id.txt_premium:
                mCurrentFragmentIndex = FRAGMENT_ONE;
                fragmentReplace(mCurrentFragmentIndex);
                getSupportActionBar().show();
                break;
            case R.id.img_self:
            case R.id.txt_self:
                mCurrentFragmentIndex = FRAGMENT_TWO;
                fragmentReplace(mCurrentFragmentIndex);
                getSupportActionBar().show();
                break;
            case R.id.img_library:
            case R.id.txt_library:
                mCurrentFragmentIndex = FRAGMENT_THREE;
                fragmentReplace(mCurrentFragmentIndex);
                getSupportActionBar().show();
                break;
            case R.id.img_say:
            case R.id.txt_say:
                mCurrentFragmentIndex = FRAGMENT_FOUR;
                fragmentReplace(mCurrentFragmentIndex);
                getSupportActionBar().show();
                break;
        }
   

 

프래그먼트 입니다.

public class PremiumFragment extends Fragment{
	View v;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		v = inflater.inflate(R.layout.premium_fragment, container, false);
		
		return v;
	}

}

 

아시는 분 부탁드립니다 ..ㅠㅠ

양꼬양 (2,040 포인트) 님이 2015년 8월 7일 질문

답변 달기

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