Ich arbeite an einem Layout für den Hauptbildschirm meiner App. Ich verwende einen RecyclerView mit einem Grid-Layout und einem CardView. Ich versuche, den Abstand zwischen den einzelnen Karten zu verringern. Ein Screenshot ist unten (mit Layoutkonturen) sowie meine Layoutdateien. Wie kann ich erreichen, dass jede Karte sowohl vertikal als auch horizontal näher zusammen kommt? Ich habe viel mit Margen gespielt, und ich kann einfach nicht den richtigen Rand oder Padding-Wert finden, um dies zu tun. Danke für jede Hilfe!Wie verringere ich den Abstand zwischen Karten in einem CardView innerhalb eines RecyclerView?
thumbnail_view.xml:
<?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:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="200dp"
card_view:cardCornerRadius="5dp"
card_view:cardMaxElevation="15dp"
card_view:cardElevation="10dp"
card_view:contentPadding="5dp"
android:padding="1dp"
card_view:cardBackgroundColor="@color/colorPrimary"
card_view:cardUseCompatPadding="true"
card_view:cardPreventCornerOverlap="false"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/card_list">
<ImageView
android:id="@+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:contentDescription="@string/video_thumbnail_description"
android:layout_weight="1"
/>
<TextView
android:id="@+id/video_title_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layout_weight="2"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.app.int_a.giantbombforandroid.main.mainscreen.MainActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/my_recycler_list"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
Haben Sie versucht, 'wrao_content' Ihre' CardView' Breite zu ändern? – azizbekian
Ich habe es nicht versucht, bis Sie es vorgeschlagen haben, aber es macht keinen Unterschied. Außerdem möchte ich, dass jede Karte die gleichen Abmessungen hat, also glaube ich nicht, dass ich 'wrap_content' sowieso haben möchte. Trotzdem danke. – intA