Cardview половината ширина на екрана

Това е моето оформление. Слагам GridView. Искам две колони в GridView, които запълват ширината на екрана. Не може да направи оформлението на CardView да запълва половината от екрана. Проследих тази връзка, но няма резултат.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="150dp" android:layout_height="wrap_content"
android:gravity="center"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="2sp"
card_view:cardUseCompatPadding="true"
card_view:contentPadding="5dp"
>
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/quote"
        android:text="jalkdjlajflkdajf akjfdlajfljal alfjk"
        android:layout_margin="3dp"
        />
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:layout_marginLeft="2dp"
        android:layout_below="@+id/quote"
        >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/time"
            android:layout_alignParentLeft="true"
            android:text="time started"
            android:layout_centerVertical="true"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/button1"
            android:layout_alignParentRight="true"
            android:text="5"
            android:layout_marginLeft="3dp"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/button2"
            android:layout_toLeftOf="@+id/button1"
            android:text="5"
            android:layout_marginLeft="3dp"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/button3"
            android:layout_toLeftOf="@+id/button2"
            android:text="5"
            android:layout_marginLeft="3dp"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/button4"
            android:layout_toLeftOf="@+id/button3"
            android:text="5"
            android:layout_marginLeft="3dp"
            />
    </RelativeLayout>
</RelativeLayout>


person Prashanth Debbadwar    schedule 06.08.2015    source източник
comment
задайте numColums на 2 GrridView автоматично създаване на две колони\   -  person N J    schedule 06.08.2015


Отговори (1)


Тъй като надувате различния файл с оформление за вашия GridView. Вашето оформление ще бъде изобразено като изглед на цял екран. Но когато дефинирате броя на колоните или кажете span на GridView, той ще има два изгледа един до друг, точно същите, които искате да постигнете.

Така че, просто във вашия GridView таг вътре в xml просто добавете

android:numColumns="2"

Или от java код.

mGridView.setNumColumns(2);
person Aawaz Gyawali    schedule 06.08.2015