두 개의 조각으로 된 활동이 있는데 하나는 목록을 표시하고 다른 하나는 클릭 한 항목의 세부 정보를 표시합니다. 앱을 시작할 때 디테일 부분은 정적인데 일단 항목을 클릭하면 해당 부분이 대체됩니다. 문제는 이전 조각이 대체되지 않아서 두보기가 서로 위에 있다는 것입니다.Android 조각이 겹칩니다.
내 활성 레이아웃이다
<?xml version="1.0" encoding="utf-8"?>
<fragment
android:id="@+id/listFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
class="com.fragments.FragmentOrderList" >
</fragment>
<fragment
android:id="@+id/detailFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
class="com.fragments.FragmentOrderDetails" >
</fragment>
상세 단편의 레이아웃은 :
<RelativeLayout 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" >
<TextView
android:id="@+id/tvOrderDetail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test view of details fragment" >
</TextView>
위의 레이아웃에서 초기에 볼 수있는 정적 텍스트를 볼 수 있습니다. 조각을 대체 할 내 활동의 코드는 다음과 같습니다.
FragmentTransaction transaction = getFragmentManager().beginTransaction();
FragmentOrderDetails newFragment = new FragmentOrderDetails();
newFragment.setArguments(b);
transaction.replace(R.id.detailFragment, newFragment);
transaction.addToBackStack(null);
transaction.commit();
내게는 "바꾸기"보다는 "추가"하는 것처럼 보입니다. 항상 이전 조각을 제거해야합니까? 아니면 다른 접근법을 따라야합니까? 그것은 원래 조각이 거기에 머무르고 두 번째, 세 번째 ...에 남아있는 것처럼 보입니다. 이전 조각이 바뀌었고, 정적 조각 만 바뀌 었습니다. 대신 레이아웃 xml fragment
에 사용
나는 이것을 알아 내기 위해 영원히 나를 필요로했습니다. 마침내 당신은 나에게 대답을 얻었다. – BlackHatSamurai