2017-02-17 4 views
0

SquareLayoutとRecyclerViewの2つのコンポーネントがあるLinearLayoutが1つあります。スクリーンの中央にSquareLayoutを、画面の下部にRecyclerViewを配置したいのですが、なぜ重力かわかりませんそれを設定するために働かない。私はアンドロイドで新しいです。私の質問がはっきりしていることを願っています。ここに私の.xmlファイルです。LinearLayoutを中央に設定する

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

<com.example.layouts.SquareLayout 
     android:id="@+id/llSelectedLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="center" 
     ></com.example.layouts.SquareLayout> 

    <android.support.v7.widget.RecyclerView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/rvImage" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     /> 

</LinearLayout> 
+0

のLinearLayoutは、私は思うが、RelativeLayoutは –

+0

ご提案いただきありがとうございますすることができ、それが私のために動作することはできません。 –

答えて

0

これを行うには、LinearLayoutではなくRelativeLayoutを使用してください。

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

    <com.example.gridcollagelayouts.SquareLayout 
     android:id="@+id/llSelectedLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:centerInParent="true" /> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/rvImage" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:below="@+id/llSelectedLayout" /> 

</RelativeLayout> 
+0

は、回答のRecyclerviewからxmlns:android = "http://schemas.android.com/apk/res/android"とxmlns:tools = "http://schemas.android.com/tools"を削除することができます – raktale

+0

@raktaleが削除されました。ありがとうございます。 –

+0

ありがとうございます。相対レイアウトを使用して動作します。 –

関連する問題