2016-06-10 7 views
0

Ich baue ein Layout, und ich möchte eine zentrierte (In der Mitte des Bildschirms) Gridview zwischen zwei relativen Layouts haben. Wie kann ich das machen?Wie kann ich eine Gridview zwischen zwei relativen Layouts platzieren?

Mein Code:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="0sp" 
     android:layout_weight="1" 
     android:background="#000000" 
     > 


    </RelativeLayout> 


    <GridView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:scrollbars="none" 
     android:numColumns="1" 
     android:padding="5dp" 
     android:id="@+id/gvMenu" 
     android:layout_gravity="center_horizontal" /> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:background="#fff" 
     android:layout_height="0sp" 
     android:layout_weight="1"> 


    </RelativeLayout> 


</LinearLayout> 

Thank yout.

+0

Sie ** konnte **. Aber * verschachtelte Layouts sind schlecht für Performances * (wenn du dich interessierst). Also, es ist besser, ein großes RelativeLayout zu haben, das all das Zeug enthält. –

+1

Vielen Dank für den Hinweis, ich habe das gleiche getan, nur mit einem relativen Layout –

+0

Was ist muuuuuuuuch besser. –

Antwort

0

Dieser Code gibt Ihnen einen Gridlayout zwischen 2 RelativeLayouts, die Größe der Layouts werden in Abhängigkeit von anpassen, was Sie in ihnen setzen, aber das Gridview wird immer zwischen ihnen

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
> 

<RelativeLayout 
    android:id="@+id/first_relativeLayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#f23f23"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="First RelativeLayout" 
     android:layout_centerHorizontal="true"/> 

</RelativeLayout> 

<GridView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:scrollbars="none" 
    android:numColumns="1" 
    android:padding="5dp" 
    android:id="@+id/gvMenu" 
    android:layout_below="@+id/first_relativeLayout" 
    android:layout_gravity="center_horizontal" /> 

<RelativeLayout 
    android:id="@+id/second_relativeLayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignBottom="@+id/gvMenu" 
    android:background="#7e92d2"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Second RelativeLayout" 
     android:layout_centerHorizontal="true"/> 

</RelativeLayout> 

Verwandte Themen