为什么ImageView不是全屏显示?

6

我正在做一个 安卓 项目。为什么 ImageView 的 id iv1 和 iv2 不在全屏中显示?我把我的 XML 放在下面:

<?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>

如果我把ImageView放在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在全屏中显示图片。

尝试一下这个 - android:scaleType=fitXY - Praveenkumar
3个回答

23
  1. 线性布局中有填充(padding)。
  2. 图片视图(imageview)中没有内容可见,所以你无法看到其内容。
  3. 你将图片视图设为不可见(invisible),所以你看不到其中的内容。
  4. 如果你不关心宽高比,请使用android:adjustViewBounds="false" 和 android:scaleType="fitXY"。

3
请使用此属性来显示图片:
android:scaleType="fitXY"

0

我看到你的两个ImageView的高度和宽度都设置为"fill_parent",所以我猜你想让它们都缩放到整个屏幕。如果你只是想让它们静静地呆在那里,不打算以后再使用它们,就加上

android:background="@drawable/your_drawable_here"

对于线性布局和相对布局,它将在布局的背景中添加一张图片,将其缩放以适应整个布局,并节省一些资源(如果我没有弄错的话)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接