3

私は自分のアプリのメイン画面のレイアウトに取り組んでいます。私はグリッドレイアウトとその中のCardViewでRecyclerViewを使用しています。私は各カード間のスペースを減らそうとしています。以下のスクリーンショット(レイアウトのアウトラインをオンにした状態)と私のレイアウトファイルです。どのようにして、各カードを垂直方向にも水平方向にも少しずつ近づけることができますか?私は余裕を持って周りを遊んでいましたが、私はちょうどこれを行うために右余白またはパディング値を見つけることができないようです。助けてくれてありがとう!RecyclerView内のCardViewでカード間のスペースを減らすにはどうすればよいですか?

enter image description here

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> 
+0

あなたの 'CardView'の幅を' wrao_content'に変更しようとしましたか? – azizbekian

+0

あなたがそれを提案するまで私は試しませんでしたが、違いはありません。さらに、各カードを同じ次元にしたいので、とにかく 'wrap_content'がほしいと思っていません。しかし、ありがとう。 – intA

答えて

5

編集これらの属性

card_view:cardMaxElevation="1dp" 
card_view:cardElevation="1dp" 

ので、完全なコードをbしますe

<?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="1dp" 
    card_view:cardElevation="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:src="@drawable/bag" 
      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:text="lovelksdjslkdjlsdj" 
      android:layout_weight="3" 
      /> 
    </LinearLayout> 
</android.support.v7.widget.CardView> 
+0

ありがとう!それはうまくいった。ちょっと奇妙なことに、仰角はカード間の間隔を制御します。私はこれが、シャドーやオフセットのようなものに影響を与えるために、ページ外の知覚された高さと関係があると考えました。 – intA

+0

@intA Lollipopの下で標高はサポートされていません。互換スペースのために余分なスペースが追加されました。より大きな潜在的な影(maxCardElevation)は、より多くのスペースが割り当てられることを意味します。これは、水平方向に '1 * maxCardElevation'、両側に垂直に' 1.5 * maxCardElevation'です。カードのデフォルトの仰角は2dpです。 –

+0

@intA 'app:cardUseCompatPadding =" true "'は、Lollipopで同じ算数と割り当てられたスペースが使用されていることを確認します。 –

関連する問題