2017-06-03 18 views
1

私が持っているこのvehicle_list_fragment_layout.xml:この方法で私のVehicleListFragmentで使用されているボタンは表示されません

<?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> 

@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、私のVehicleListFragmentをホストActivityのレイアウトです:

<?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使用。 ありがとうございます!

EDIT

これは私の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> 
+0

あなたのボタン'recycler_view_fragment_layout'レイアウトの下にあります。 – Stanojkovic

+0

@Stanojkovic私はそうは思わない: 'vehicle_list_fragment_layout'を' ScrollView'でラップし、私のボタンはまだ表示されていません。 – Clyky

+0

'ScrollView'の高さを確認してください。 – Stanojkovic

答えて

1

はこれを試してみてください。私は以下に追加のようなリサイクルビューとボタンを表示するだけでなく、親にオリエンテーションを追加する必要があり、自分の子供に、親ビューとlayout_weightに

<?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:orientation="vertical" 
    android:layout_height="match_parent" 
    android:weightSum="1"> 

    <android.support.v7.widget.RecyclerView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:scrollbars="vertical" 
     android:layout_weight=".8" 
     android:id="@+id/recyclerView"> 
    </android.support.v7.widget.RecyclerView> 

    <Button 
     android:id="@+id/btnAddVehicle" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight=".2" 
     android:text="+" /> 
</LinearLayout> 

をweightsumを追加Basicall垂直

+0

あなたの答えのおかげで、しかし、あなたのソリューションが動作しません、私のボタンはまだ見えない – Clyky

+0

は、あなたのrecycler_view_fragment_layout –

+0

ないok投稿、私は今、私のコードを使用して – Clyky

0

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" 
    android:orientation="vertical"> 

    <include 
     layout="@layout/recycler_view_fragment_layout"/> 

    <Button 
     android:id="@+id/btnAddVehicle" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="+"/> 

</LinearLayout> 

recycler_view_fragment_layout.xmlで :

<?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" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:orientation="vertical" 
    tools:layout_height="match_parent" 
> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recyclerView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:scrollbars="vertical"/> 

</LinearLayout> 
+0

'layout_weight'は' includeタグに適用できません – Clyky

+0

これは間違っています、タグを含めるためにウェイトを適用することはできません –

+0

私の答え、含まれているレイアウトに1の重みを加えて同じままです。含まれているレイアウトでは、 'android:layout_height =" 0dp "'はパフォーマンスに役立ち、 'tools:layout_height =" match_parent "'はレイアウトのレンダリングをエディタで見ることができます。 – Wang

関連する問題