LoginSignup
0
0

More than 5 years have passed since last update.

CardViewを横いっぱいに広げる

Last updated at Posted at 2017-10-13

CardViewの使い方メモ

こまったこと

CardView内の各要素のlayout_widthを"match_parent"に設定しても、CardViewが横いっぱいに広がらない。
イメージ3.png

※使用したソースコード

<?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/cardView"
    android:layout_marginBottom="10dp"
    card_view:cardBackgroundColor="#ffc"
    card_view:cardCornerRadius="7dp"
    card_view:cardElevation="5dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <TextView
                android:layout_weight="7"
                android:layout_width="0dp"
                android:id="@+id/pointView"
                android:textSize="15sp"/>

            <!--0dpがないと、@+id/titleViewの文字列長にあわせて、レイアウト比率がずれる-->
            <TextView
                android:layout_weight="3"
                android:layout_width="0dp"
                android:text="test"/>

        </TableRow>

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/titleView"
                android:textSize="15sp"/>

        </TableRow>

    </TableLayout>

</android.support.v7.widget.CardView>

解決方法

CardViewを乗せるRecycleLayoutのlayout_widthを、"wrap_content"からmatch_parent"に変更する。
        <android.support.v7.widget.RecyclerView
            android:id="@+id/rv"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </android.support.v7.widget.RecyclerView>

解決した
image1.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0