2015-11-07 77 views
0

所以我想要做的是在每张卡片内部都有一个带有图像的回收器视图。Android上的Cardview尺寸

我怎样才能知道每个卡的宽度,以便我可以将图像传递给具有确切大小的适配器并占用整个卡的空间? (我希望图像的尺寸完全相同)。

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/card_view" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    card_view:cardCornerRadius="4dp" 
    android:layout_margin="5dp"> 

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


     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="160dp" 
      android:id="@+id/phone_card_imageView" 
      android:layout_alignParentTop="true" 
      android:layout_centerHorizontal="true"/> 


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

这是我在cardview上的代码。

回答

0

layout_widthlayout_height更改为dp中的固定尺寸,以便您的ImageView这样做。 请注意,您也可以只固定高度,宽度将是屏幕的一个。

+0

这并没有解决问题,但我做到了卡的大小,现在我确切知道我需要什么样的图像 –

+0

哦,我没有看到你的卡有match_parent。列表项目的布局应该总是将其内容包装为高度,或者至少需要修正大小,所以在这里您遇到了问题 –