如何在 CardView 中获得红色的空白空间?

亲爱的 Android 开发人员,我正在创建 cv Android 应用程序,但是 CardView 中的 TextView 之后是空的,我该如何摆脱那个空间

http://img3.mukewang.com/61b300590001817507191279.jpg

在我的 xml 代码下面,我已经将 CardView 作为父子实现为 LinearLayout。


<?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="match_parent"

    android:layout_height="match_parent"

    card_view:cardCornerRadius="0dp"

    card_view:cardPreventCornerOverlap="true"

    card_view:cardUseCompatPadding="true">


    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:orientation="vertical">



        <ImageView

            android:id="@+id/imageView"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:layout_margin="30dp"

            android:scaleType="centerCrop" />



        <Space

            android:layout_width="50dp"

            android:layout_height="20dp" />



        <TextView

            android:id="@+id/about"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:layout_marginTop="16dp"

            android:layout_marginRight="250dp"

            android:gravity="center"

            android:text="@string/about_me"

            android:textSize="16sp"

            android:textStyle="bold" />


        <TextView

            android:id="@+id/introduction"

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:layout_marginTop="16dp"

            android:gravity="start" />


    </LinearLayout>


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


翻过高山走不出你
浏览 172回答 3
3回答

天涯尽头无女友

减少文本视图的边距顶部也删除空间标签并减少图像视图的边距

桃花长相依

将卡片视图的布局高度更改为 match_parent

米脂

在您的卡片视图中使用此属性,您可以看到不同之处您的卡片没有高度和半径,并且卡片视图合并到活动中,这就是为什么它在文本后显示为空格的原因在卡片视图中使用它:&nbsp;<?xml version="1.0" encoding="utf-8"?>&nbsp; &nbsp; <RelativeLayout&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; xmlns:android="http://schemas.android.com/apk/res/android"&nbsp; &nbsp; &nbsp; &nbsp; xmlns:card_view="http://schemas.android.com/apk/res-auto"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_margin="8dp">&nbsp; &nbsp; &nbsp; &nbsp; <android.support.v7.widget.CardView&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns:android="http://schemas.android.com/apk/res/android"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; card_view:cardCornerRadius="8dp"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; card_view:cardElevation="6dp"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:elevation="4dp">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <LinearLayout&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_marginBottom="8dp"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:orientation = "vertical">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <ImageView&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/imageView"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_margin="30dp"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:scaleType="centerCrop" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <TextView&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/about"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_marginTop="16dp"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_marginRight="250dp"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:gravity="center"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:text="@string/about_me"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:textSize="16sp"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:textStyle="bold" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <TextView&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/introduction"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_marginTop="16dp"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:gravity="start" />&nbsp; &nbsp; &nbsp; &nbsp; </LinearLayout>&nbsp; &nbsp; </android.support.v7.widget.CardView>&nbsp; &nbsp; </RelativeLayout>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java