2017-02-17 5 views
0

У меня есть один LinearLayout, в котором есть два компонента: SquareLayout, а второй - RecyclerView, я хочу SquareLayout в центре экрана и RecyclerView в нижней части экрана, не знаю, почему, но гравитация не работает для его установки. Я новичок в android. Надеюсь, мой вопрос ясен. Вот мой .xml файл.set LinearLayout on center android

<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

Используйте RelativeLayout вместо LinearLayout для этого.

<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

может захотеть удалить xmlns: android = "http://schemas.android.com/apk/res/android" и xmlns: tools = "http://schemas.android.com/tools" из Recyclerview в ответе – raktale

+0

@raktale удален, спасибо –

+0

Спасибо. Он будет работать с использованием Relative Layout. –