2013-07-22 58 views
3

我編程的Android應用程序,我有下一個問題:我的ImageView取決於圖像大小的改變(安卓)

我需要顯示通過HTTP下載圖片到包含列表視圖和ImageView的和文本。雙方或其中包含在LinearLayout中:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal" > 

<ImageView 
    android:id="@+id/imagenEvento" 
    android:layout_width="80dp" 
    android:layout_height="80dp" 
    android:scaleType="fitXY" 
    android:adjustViewBounds="true" 
    android:paddingBottom="2dp"  
    android:contentDescription="@string/contenidoImagen"  

    /> 


<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="left" 
    android:padding="10dp" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/titulo" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="17sp" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <TextView 
     android:id="@+id/sitio" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="12sp" 
     android:textAppearance="?android:attr/textAppearanceSmall" /> 

    <TextView 
     android:id="@+id/fecha" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="12sp" 
     android:textAppearance="?android:attr/textAppearanceSmall" /> 

</LinearLayout> 

Iload的圖像dinamically不同大小和,但是當我加載它們中的一些,我的ImageView的大小受到影響,它不會尊重我的身高和寬度聲明。

我試圖建立最大和最小尺寸,我已經在代碼中定義了佈局參數,建立了填充底部,重新設置了位圖,但沒有任何效果。

在接下來的畫面中的黃色圓圈顯示相同的空間和紅色的ImageView的和行 http://imageshack.us/photo/my-images/32/csww.jpg/

我缺少的底部之間不同的空間?

+0

沒有耶調整,它沒有工作,我不斷獲得相同的結果 – n4h1n

+1

但ImageVIew保持他的大小,右LinearLayout包含TextViews是根據行改變 –

+0

@MarcinGawel ImageView我我認爲這是不斷變化的。 TextViews正在改變取決於行,這是正確的,但它不應該影響ImageView的大小 – n4h1n

回答

3

你可以試試這段代碼。如果這個力的工作,那麼你可以使用的RelativeLayout並把所有的圖像查看和文本的佈局,並嘗試在相對佈局

<ImageView 
    android:id="@+id/imagenEvento" 
    android:layout_width="80dp" 
    android:layout_height="fill_parent" 
    android:scaleType="fitXY" 
    android:adjustViewBounds="true" 
    android:paddingBottom="2dp"  
    android:contentDescription="@string/contenidoImagen"  

    /> 

OR

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <RelativeLayout 
     android:id="@+id/relativeLayout1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="@android:color/darker_gray" 
     android:layout_alignParentTop="true" > 

     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="10dp" 
      android:src="@drawable/ic_launcher" /> 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_marginLeft="16dp" 
      android:layout_toRightOf="@+id/imageView1" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:text="TextView" /> 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignLeft="@+id/textView1" 
      android:layout_below="@+id/textView1" 
      android:text="Content Name" /> 

     <TextView 
      android:id="@+id/textView3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignLeft="@+id/textView2" 
      android:layout_below="@+id/textView2" 
      android:text="29/02/2009" /> 
    </RelativeLayout> 

</RelativeLayout> 

enter image description here

+0

它工作正常,我只是改變了 android:layout_width =「80dp」 android:layout_height =「80dp」,唯一的問題是,ImageViews正在改變它們的大小,我不希望發生這種情況 – n4h1n

+0

Okey雅tats罰款 –

0

爲什麼你使用android:adjustViewBounds如果你想爲你的ImageView指定尺寸? 使用android:adjustViewBounds,您的ImageView將更改其大小以保持圖像的寬高比。

如果您想以true 80x80顯示圖像 - 刪除android:adjustViewBounds並將scaleType更改爲centerCrop。這樣,圖像將盡可能多地縮小,因此這兩個尺寸都會觸摸ImageView邊界,其餘部分將被裁剪。

或者使用scaleType =「centerInside」如果你想爲圖像可見完全(那會看起來醜陋保證100%:d)

無論哪種方式,安卓adjustViewBounds莫屬。

+0

它的工作變化,我讓你說,變化及其OK!謝謝! – n4h1n