Android 用片段替换片段,什么也不会发生
我想通过单击imageview从fragment5转到fragment6 这是我的片段5 xmlAndroid 用片段替换片段,什么也不会发生,android,android-fragments,Android,Android Fragments,我想通过单击imageview从fragment5转到fragment6 这是我的片段5 xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" an
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"/>
<TextView
android:id="@+id/textfrag5label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="header" />
<TextView
android:id="@+id/textfrag5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="39dp"
android:textStyle="bold"
android:text="foo "
android:layout_below="@+id/toolbar"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageView
android:id="@+id/forwardfrag5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textfrag5label"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="23dp"
android:layout_marginRight="23dp"
app:srcCompat="@drawable/ic_arrow_forward_black_24dp"
android:onClick="clickEvent"/>
<FrameLayout
android:id="@+id/show_fragment"
android:layout_width="match_parent"
android:layout_height="0dp">
</FrameLayout>
</RelativeLayout>
}这是因为您将容器的高度设置为0dp,事实上您的碎片6已连接,但您无法看到它 您可以修改容器的高度
<FrameLayout
android:id="@+id/show_fragment"
android:layout_width="match_parent"
android:layout_height="0dp"><!--modify 0dp to some you need-->
</FrameLayout>
您想让fragment自行替换吗?不,当我在fragment5中时,我想通过单击带有“前进符号”图标的imageview按钮转到fragment 6。您的代码看起来仍然不太好。首先,您似乎将onclicklistener附加到wholefragment,而不是图像视图,然后事务也在该片段中。它应该移到父容器(即父活动)中,fragment5在单击时应该做的唯一一件事是告诉父对象它是clickedI,我对“片段”是新手,因此对我来说有点困难。你有没有什么好的例子可以让我更好地理解你刚才告诉我的话?不幸的是,这不起作用。我仍然处于支离破碎的状态。
<FrameLayout
android:id="@+id/show_fragment"
android:layout_width="match_parent"
android:layout_height="0dp"><!--modify 0dp to some you need-->
</FrameLayout>