2017-02-22 55 views
0

我有一个recyclerview,里面有一个NetworkImageView和一些文本视图。NetworkImageView和TextView之间的空间取决于图像的大小

问题是,根据NetworkImageView上的图像,空白区域会发生变化(我注意到图像很小时没有添加空间,另一方面,如果图像很大,图像和textview之间会添加更大的空白区域。

space no space 所以在第一张照片有图像和名称/发行商之间有很大的空间。

<?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> 

我怎样才能消除这种空间或添加自己(而不是这个随意的事情)?

回答

1

如果您调试布局,您可能会发现NetworkImageView实际上占据了空白区域,但图像比例不会让它填满整个空间。尝试添加

android:adjustViewBounds="true" 

到NetworkImageView。

+0

你真了不起,谢谢! –

相关问题