Кардвью на половину ширины экрана

Это мой макет. Я вставляю 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