2012-05-22 123 views
6

我在做一個Android項目。爲什麼ImageView id iv1和iv2不是全屏顯示?我已經把我的XML到這裏:爲什麼ImageView不能全屏顯示?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/layout1" 
       android:orientation="vertical" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:paddingBottom="10px" 
       android:paddingLeft="10px" 
> 
    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
    > 
     <ImageView 
      android:id="@+id/iv1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:visibility="invisible" 
     /> 

     <ImageView 
      android:id="@+id/iv2" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:visibility="invisible" 
     /> 

      <ImageButton 
      android:id="@+id/menu_btn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_toRightOf="@+id/BunyiIng" 
      android:src="@drawable/menu_btn" 
      android:background="@null" 
     /> 

     <ImageView 
      android:id="@+id/image_logo" 
      android:src="@drawable/logo_vehicle" 
       android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@null" 
      android:layout_marginTop="5px" 
     /> 

    </RelativeLayout> 
</LinearLayout> 

如果我把ImageViews中的LinearLayout,它擋住了RelativeLayout的。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/layout1" 
       android:orientation="vertical" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:paddingBottom="10px" 
       android:paddingLeft="10px" 
> 
    <ImageView 
      android:id="@+id/iv1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:visibility="invisible" 
    /> 

    <ImageView 
     android:id="@+id/iv2" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:visibility="invisible" 
    /> 

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

但如果ImageView的放置在下面的RelativeLayout,但內部的LinearLayout中,ImageView的未示出的圖像。

</RelativeLayout> 

    <ImageView 
      android:id="@+id/iv1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:visibility="invisible" 
    /> 

    <ImageView 
      android:id="@+id/iv2" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:visibility="invisible" 
    /> 
</LinearLayout> 

我該如何解決?我希望ImageView以全屏顯示圖像。

+0

試試這個 - 「android:scaleType = fitXY' – Praveenkumar

回答

24
  1. 您有線性佈局填充。
  2. 您在imageview中沒有任何內容查看其內容,因此您無法看到其內容。
  3. 您已將imageview設置爲不可見,因此您無法看到其內容。
  4. 如果您不關心寬高比,請使用android:adjustViewBounds =「false」和android:scaleType =「fitXY」。
+2

答案沒有4它的作品!你救了我的生活。謝謝!! – user1008497

2

使用該屬性爲圖像視圖:

android:scaleType="fitXY" 
0

我看到你的兩個ImageViews的高度和寬度都設置爲「fill_parent」,所以我猜你希望它們都可以縮放到整個屏幕。在你想他們只是坐在那裏,不打算以後將其用於任何情況下,加

android:background="@drawable/your_drawable_here" 

你的線性和相對佈局兩者。它會將圖像添加到佈局的背景中,將其縮放以適應整個佈局,並且如果我沒有弄錯,則可以節省一些資源。