Android XML问题-图像未在AVD中显示



我对android还很陌生,但我已经弄清楚了所有布局的东西是如何使用XML的。没关系。

在Eclipse的"图形布局"选项卡中,我有几个按钮和一个.gif图像的徽标。我已经将.gif图像作为LinearLayout中的ImageView放置到我的XML文件中,它显示在图形布局中。

但当我在安卓虚拟设备(AVD)中运行它时,除了图像之外,其他一切都会显示出来。有人知道为什么会发生这种事吗?请参阅下面的XML代码。。。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/natlib"
android:orientation="vertical" >
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="-8dp"
        android:padding="@dimen/padding_medium"
        android:text="@string/welsh_libs"
        android:textColor="#79438F"
        android:textSize="22dip"
        android:textStyle="bold"
        tools:context=".MainActivity" />
</LinearLayout>
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
    <Button
        android:id="@+id/button1"
        android:layout_width="137dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="25dp"
        android:background="#A4C81C"
        android:text="@string/ask_lib" />
    <Button
        android:id="@+id/button2"
        android:layout_width="137dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="25dp"
        android:background="#FF0066"
        android:text="@string/find_book" />
    <Button
        android:id="@+id/button3"
        android:layout_width="137dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="25dp"
        android:background="#3F83F1"
        android:text="@string/find_lib" />
    <Button
        android:id="@+id/button4"
        android:layout_width="137dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="25dp"
        android:background="#FE0002"
        android:text="@string/register" />
    <Button
        android:id="@+id/button5"
        android:layout_width="137dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:background="#FBFC3F"
        android:text="@string/login" />
    <ImageView
        android:id="@+id/image1"
        android:layout_width="wrap_content"
        android:layout_height="0dip"
        android:layout_marginLeft="220dp"
        android:layout_marginTop="20dp"
        android:layout_weight="0.37"
        android:contentDescription="@string/desc"
        android:src="@drawable/wag_logo"
        android:visibility="visible" />
</LinearLayout>

设置android:layout_height大于0…尝试此

  <ImageView
    android:id="@+id/image1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="220dp"
    android:layout_marginTop="20dp"
    android:layout_weight="0.37"
    android:contentDescription="@string/desc"
    android:src="@drawable/wag_logo"
    android:visibility="visible" />

您将图像放在哪个文件夹中/res/drawable?此外,您将布局放置在哪个文件夹中/res/layout

/res/文件夹及其子文件夹用于本地化。

因此,如果你只在/res/drawable-xhdpi/中有它,它只会出现在非常大的设备上。

此外,如果您在/res/layout-large/修改了布局文件,而没有在/res/layout修改布局文件,则只有大版本才会得到修改。

最新更新