2017-04-11 102 views
-1

我有與此圖像項目的列表視圖:機器人列表視圖與圖像項目來調整圖像高度proportionaly

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/llItem" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_marginTop="5dp" 
android:background="@color/white" 

android:layoutDirection="rtl" 
android:orientation="horizontal"> 

<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:layout_marginTop="5dp" 
    android:background="@color/white" 
    app:cardElevation="4dp" 
    app:cardUseCompatPadding="true"> 

    <ImageView 
     android:id="@+id/pollimg" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 


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

我需要在getview方法的圖像視圖加載到陣列適配器如下:

    @Override 
public void onBindViewHolder(ViewHolder viewHolder, final int position) { 
       .... 
       etc 
       ..... 
     try { 
      Picasso.with(context) 
        .load(allpolls.get(position).getMediaUrl()).fit() 
        .placeholder(R.mipmap.icon).into(holder.img); 
     } catch (Exception e) { 
      holder.img.setVisibility(View.GONE); 
     } 
     } 

我的問題是,所有行的imageview高度是固定的,我需要將imageview高度設置爲與在線圖像相同的圖像高度。所以它可以採取它的確切高度

+0

發表您的完整佈局...代碼 – rafsanahmad007

+0

問題是更新PLZ檢查 – Amalo

回答

1

this教程

擬合()是測量目標的ImageView的尺寸和內部使用調整大小()來將圖像尺寸減小到的ImageView的尺寸。關於fit()有兩件事要知道。首先,調用fit()可以延遲圖像請求,因爲畢加索需要等待ImageView的大小才能被測量。其次,您只能將fit()與ImageView用作目標。

這意思,如果您使用fit()圖像將被調整大小。去掉它。

如需進一步信息,如果你想保持圖像的原始寬高比,你應該考慮把高度和寬度wrap_content

+0

這就是它!我也加入到imageview工作得很好 'android:adjustViewBounds =「true」' – Amalo

+0

很高興爲您提供幫助。這也保留了圖像的寬高比 – Ricardo