【问题标题】:Space between NetworkImageView and TextView depending on image sizeNetworkImageView 和 TextView 之间的空间取决于图像大小
【发布时间】:2017-02-22 10:48:50
【问题描述】:

我有一个recyclerview,里面有一个NetworkImageView 和一些文本视图。

问题是,根据NetworkImageView 上的图像,空白空间会发生变化。(我注意到如果图像很小,则不会添加空间,另一方面,如果图像很大,则会在图像和 @ 之间添加更大的空白空间987654328@.

所以在第一张图片中,图片和名称/发布者之间有很大的空间。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:padding="@dimen/activity_horizontal_margin"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <com.android.volley.toolbox.NetworkImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="0dp"
                android:id="@+id/imageViewHero" />

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

                <TableRow>
                    <TextView
                        android:text="Name"
                        android:paddingRight="10dp"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        />

                    <TextView
                        android:id="@+id/textViewName"
                        android:textStyle="bold"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        />

                </TableRow>

                <TableRow>
                    <TextView
                        android:text="Publisher"
                        android:paddingRight="10dp"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        />

                    <TextView
                        android:id="@+id/textViewPublisher"
                        android:textStyle="bold"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        />

                </TableRow>

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

</RelativeLayout>

我怎样才能删除这个空间或添加我自己的(而不是这个随机的东西)?

【问题讨论】:

    标签: android android-layout android-studio android-xml


    【解决方案1】:

    如果你调试你的布局,你可能会发现 NetworkImageView 实际上占据了空白空间,但是图像比例并没有让它填满整个空间。尝试添加

        android:adjustViewBounds="true"
    

    到 NetworkImageView。

    【讨论】: