我有這個vehicle_list_fragment_layout.xml
:按鈕不是線性佈局內可見
<?xml version="1.0" encoding="utf-8"?>
<!-- Layout per il fragment VehicleListFragment. -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/recycler_view_fragment_layout"/>
<Button
android:id="@+id/btnAddVehicle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="+"/>
</LinearLayout>
它以這種方式使用我的VehicleListFragment
:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View rootView = inflater.inflate(R.layout.vehicle_list_fragment_layout, container, false);
btnStartActivity = (Button) rootView.findViewById(R.id.btnAddVehicle);
mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView);
mLayoutManager = new LinearLayoutManager(getActivity());
setRecyclerViewLayoutManager(LayoutManagerType.LINEAR_LAYOUT_MANAGER);
initAdapter();
mRecyclerView.setAdapter(mAdapter);
setButtonClickListener();
return rootView;
}
的問題是RecyclerView
顯示正確,但我未顯示btnAddVehicle
。
這是activity_vehicle_layout.xml
的Activity
佈局哪些主機我VehicleListFragment
:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="clyky.cartracker.activities.VehicleActivity">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/vehicleContainer">
</FrameLayout>
</android.support.constraint.ConstraintLayout>
我用vehicleContainer
作爲容器我的片段。 在此先感謝!
編輯
這是我recycler_view_fragment_layout
:
<?xml version="1.0" encoding="utf-8"?>
<!-- Layout per un fragment che contiene una RecyclerView -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:id="@+id/recyclerView">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
您的按鈕在'recycler_view_fragment_layout'佈局下。 – Stanojkovic
@Stanojkovic我不這麼認爲:我用'ScrollView'包裹了我的'vehicle_list_fragment_layout',我的按鈕還沒有顯示出來 – Clyky
檢查你的'ScrollView'高度。 – Stanojkovic