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

fragment 화면 전환 질문입니다.

0 추천

activity_main.xml에서 fragment 부분에 fragment_one.xml과 fragment_two.xml 레이아웃을 사용하려고합니다.

초기 실행 시 위 사진처럼 fragmnet 부분에 해당 fragment_one.xml 파일이 잘 들어간것을 확인할 수 있는데요.

그다음 기능2버튼을 누르고 fragment_two.xml로 넘어갈때와 fragment_one.xml로 다시 레이아웃 전환을 했을때,

다음과 같이 레이아웃에 문제가 생깁니다.

기능4버튼 아래 부분에 fragment_one.xml의 일부가 보이면서 텍스트뷰도 정상적으로 보이지않습니다.

width,height 부분에서 설정이 뭔가 잘못된 것 같으나, 아무리 수정을 해봐도 일부가 보이는 부분이 달라지고

완벽히 xml간 전환되지 않는 문제가 항상 발생합니다. 안드로이드 초보 개발자라 조언 주시면 감사하겠습니다.

 

소스코드 첨부합니다.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <Button
        android:id="@+id/btn"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="접속"
        android:onClick="onClick"/>
    <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="기능1"
        android:onClick="selectFrag" />
    <Button
        android:id="@+id/button2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:onClick="selectFrag"
        android:text="기능2" />
    <Button
        android:id="@+id/button3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:onClick="selectFrag"
        android:text="기능3" />
    <Button
        android:id="@+id/button4"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:onClick="selectFrag"
        android:text="기능4" />
    <fragment
        android:name="com.example.chatclient.FragmentOne"
        android:id="@+id/fragment_placee"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</LinearLayout>

activity_main.xml

 

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#00ffff">


    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"/>

    <EditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ffdd00"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/btn_send"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="전송"
        android:onClick="onClick"
        android:layout_weight="1"
        android:layout_gravity="center_horizontal"/>
</LinearLayout>

fragment_one.xml

 

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffff00">

    <TextView
        android:id="@+id/textView2"
        android:text="This is fragment No.2"
        android:textStyle="bold"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


</LinearLayout>

fragment_two.xml

 

감사합니다.

andro9090 (120 포인트) 님이 2015년 8월 27일 질문

답변 달기

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