我有一个ListFragment浮动操作按钮。当按钮被点击时,我想用CreateListFragment替换ListFragment。相反,CreateListFragment放置在ListFragment的顶部,并且ListFragment中的按钮和文本视图仍然可见。我不确定哪里出了问题。我如何完全用CreateListFragment替换ListFragment?片段交易
这里是按钮被点击之前 http://i.stack.imgur.com/k2HxP.png
这里是按钮被点击后,屏幕截图的截图 http://i.stack.imgur.com/TYN47.png
list_fragment
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listFrame">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/fab"
android:layout_gravity="bottom|end"
app:backgroundTint="@color/colorAccent"
android:src="@drawable/create"/>
<TextView
android:id="@+id/tvEmpty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="No Shopping Lists Yet"
android:layout_gravity="center"
android:textSize="20sp"/>
</FrameLayout>``
createlist_fragment
<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"
android:padding="10dp"
tools:context="com.lavineoluoch.helloworld.swiftpay.app.CreateListFragment">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/etListTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/title"/>
<EditText
android:id="@+id/etAddItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/items"/>
<RelativeLayout
android:id="@+id/buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/btnEditItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btnEdit"
android:background="@color/colorPrimary"
android:textColor="@color/white"
/>
</RelativeLayout>
</LinearLayout>
ListFragment.java
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
final View view = inflater.inflate(R.layout.list_fragment, container, false);
fab = (FloatingActionButton)view.findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CreateListFragment createListFragment = new CreateListFragment();
android.support.v4.app.FragmentTransaction fragmentTransaction = getActivity().getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.listFrame,createListFragment);
fragmentTransaction.commit();
}
});
return view;
}
尝试fab.hide();点击那个 – VVB
我已经试过了,没有工作。但是,谢谢你的建议。下面的答案适用于我。 – Evo