java - Cardview 没有占据全宽(从左边裁剪 2%)

标签 java android android-layout android-cardview

我有一个具有以下布局的卡片 View :

- Main Relative Layout
-- Header Container ( Linear )
-- Body Container ( Linear )
-- Footer Container ( Linear )

卡片 View 从左边裁剪 2%,不是全宽,您可以通过比较边框(半径)和卡片与末端之间的差异来判断。

截图:HERE .

我的布局:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:id="@+id/cardView"
    android:foreground="?attr/selectableItemBackground"
    android:stateListAnimator="@anim/lift_on_touch">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:id="@+id/linearLayout2"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginTop="5dp"
            android:layout_marginStart="5dp"
            android:layout_marginEnd="5dp"
            android:layout_marginRight="5dp"
            android:layout_marginLeft="5dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="start"
                android:gravity="start"
                android:textSize="15dp"
                android:text="Test League"
                android:id="@+id/league"
                android:layout_margin="5dp" />


            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#32000000"
                android:layout_gravity="center"
                android:layout_marginStart="8dp"
                android:layout_marginEnd="8dp"
                android:layout_marginRight="8dp"
                android:layout_marginLeft="8dp" />

        </LinearLayout>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:id="@+id/match_container"
            android:layout_alignLeft="@+id/linearLayout2"
            android:layout_below="@+id/linearLayout2">

            <RelativeLayout
                android:orientation="vertical"
                android:layout_width="0dp"
                android:layout_weight="0.3"
                android:layout_height="wrap_content"
                android:id="@+id/first_team_container">

                <ImageView
                    android:layout_width="wrap_content"
                    android:gravity="center"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="15dp"
                    android:id="@+id/first_team_icon"
                    android:layout_alignParentTop="true"
                    android:layout_centerHorizontal="true" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="First Team"
                    android:gravity="center"
                    android:textSize="13sp"
                    android:id="@+id/first_team_title"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentEnd="true"
                    android:layout_below="@+id/first_team_icon" />
            </RelativeLayout>

            <RelativeLayout
                android:orientation="horizontal"
                android:layout_width="0dp"
                android:layout_weight="0.1"
                android:layout_height="100dp"
                android:layout_alignParentTop="true"
                android:layout_toRightOf="@+id/first_team_container"
                android:layout_toEndOf="@+id/first_team_container"
                android:id="@+id/match_result">


                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:gravity="center"
                    android:layout_height="match_parent">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textSize="20sp"
                        android:id="@+id/first_result"
                        android:layout_gravity="center_vertical" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="-"
                        android:textSize="20sp"
                        android:layout_marginLeft="5dp"
                        android:layout_marginRight="5dp"
                        android:layout_marginEnd="5dp"
                        android:layout_marginStart="5dp"
                        android:id="@+id/dash"
                        android:layout_gravity="center_vertical" />


                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textSize="20sp"
                        android:id="@+id/second_result"
                        android:layout_gravity="center_vertical" />

                </LinearLayout>
            </RelativeLayout>

            <RelativeLayout
                android:orientation="vertical"
                android:layout_width="0dp"
                android:layout_weight="0.3"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_toRightOf="@+id/match_result"
                android:layout_toEndOf="@+id/match_result"
                android:id="@+id/second_team_container">

                <ImageView
                    android:layout_width="wrap_content"
                    android:gravity="center"
                    android:layout_marginTop="15dp"
                    android:layout_alignParentTop="true"
                    android:layout_centerHorizontal="true"
                    android:layout_height="wrap_content"
                    android:id="@+id/second_team_icon" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Second Team"
                    android:gravity="center"
                    android:textSize="13sp"
                    android:id="@+id/second_team_title"

                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentEnd="true"
                    android:layout_below="@+id/second_team_icon" />

            </RelativeLayout>

        </LinearLayout>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:id="@+id/info_container"
            android:layout_below="@+id/match_container"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginBottom="5dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Status"            android:textSize="12sp"

                android:id="@+id/status" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_marginStart="10dp"
                android:layout_marginLeft="10dp"
                android:textSize="12sp"
                android:layout_height="wrap_content"
                android:text="Date"
                android:id="@+id/date" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="10dp"
                android:layout_marginLeft="10dp"
                android:textSize="12sp"

                android:text="Time"
                android:id="@+id/time" />
        </LinearLayout>

    </RelativeLayout>

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

</RelativeLayout>

最佳答案

在您的 CardView 中删除此行 android:layout_margin="10dp"

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/cardView"
    android:foreground="?attr/selectableItemBackground"
    android:stateListAnimator="@anim/lift_on_touch">

更新:

android:padding="10dp" 添加到 cardview 的父 relativelayout。

关于java - Cardview 没有占据全宽(从左边裁剪 2%),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37018585/

相关文章:

android - 如何从 Android 中的 EditText 中读取单个字符?

android - android中静态内容下部分布局的选项卡

android-studio - 默认显示布局的横向版本

java - jsp中无法连接mysql数据库

java - 当键盘按下时,某些布局不会绘制

android - GoogleNetHttpTransport.newTrustedTransport() 返回 Null

Android AutoResizeTextView - 调整大小后关闭垂直重力

java - 通过 TCP 套接字发送数据包

Java - 如何将类中的值设为 'return'

java - 多边形 "Fixing"算法