我有一個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