2010-11-18 17 views
1

我在xml中有一個ImageView(image_view),我的佈局引力設置爲居中,並將比例設置爲center_inside ....但是當我將壓縮的bmp傳遞給image_view時,它將它放在屏幕的中間左側(縱向模式)......有關解決方法的任何想法?無法在ImageView上對位圖進行居中

這裏我將它設置爲圖像視圖:

 ImageView imageView = (ImageView) findViewById(R.id.image_view); 

     imageView.setImageBitmap(bitmap565); 

我也壓縮它的輸出流:

 try { 
      FileOutputStream fos = new FileOutputStream(filepath); 

      bitmap565.compress(CompressFormat.JPEG, 90, fos); 

      fos.flush(); 
      fos.close(); 
     } catch (FileNotFoundException e) { 
      e.printStackTrace(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 

謝謝大家!

<ImageButton android:id="@+id/ImageButton01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/results" android:layout_gravity="top|center"></ImageButton><ImageView 
      android:screenOrientation="portrait" 
      android:layout_width="fill_parent" 
      android:id="@+id/image_view" 
      android:layout_gravity="center" android:layout_weight="1.0" android:layout_height="wrap_content" android:scaleType="centerInside"/> 

    <Button 
      android:screenOrientation="portrait" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" android:layout_width="fill_parent" android:textStyle="bold" android:id="@+id/detect_face" android:text="Detect"/> 

+0

粘貼XML佈局,請。 – Cristian 2010-11-18 18:55:21

+0

編輯 - 對不起格式不好 – Sapp 2010-11-18 18:57:05

+0

你可以發佈完整的佈局嗎?或者至少,所有的父母?順便說一下ImageViews沒有重力。 – 2010-11-18 21:26:48

回答

1

你可以使用FrameLayout來解決你的問題。

1

ImageViewlayout_width設置爲fill_parent,所以layout_gravity不會其父內影響其水平位置。嘗試使用gravity而不是layout_gravitywrap_content而不是fill_parent

+0

嘿 - 我試過了,但它仍然顯示在中心的左側。我強迫應用程序使用縱向而不是橫向 - 您認爲這是一個問題嗎? – Sapp 2010-11-18 21:19:52

+0

這些視圖的容器是什麼?它也應該是layout_width =「fill_parent」。 – 2010-11-18 21:21:57