【问题标题】:Android background image not shown in device?Android背景图片未显示在设备中?
【发布时间】:2012-03-09 11:11:07
【问题描述】:

我将以下代码添加到 main.xml 以将图像设置为我的应用的背景图像:

android:background="@drawable/bg"

所以main.xml 看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
xmlns:android= "http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="bottom|fill_vertical"
android:background="@drawable/bg0"
>
<EditText
    android:id="@+id/edWord"
    android:layout_width="fill_parent"
    android:layout_height="53px"
    android:textSize="20px"
    android:singleLine="true"
    android:hint="" 
/>
<LinearLayout xmlns:android=
    "http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scrollbars="vertical"
    android:layout_weight="1"
    >
    <ListView android:id="@+id/lstWord"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
    />

</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="horizontal"
>
    <ImageButton
        android:id="@+id/btnGetText"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:src="@drawable/get"
        android:layout_weight="0.25"
    />
    <ImageButton
        android:id="@+id/btnFind"
        android:text="Click me..."
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:src="@drawable/find"
        android:layout_weight="0.25"
    /> 

</LinearLayout>
</LinearLayout>

当然,bg.png 的图像在 drawable 中。

问题是背景图像仅显示在模拟器中,而不显示在我的实际设备(HTC Desire)中。

我做错了什么?我需要做些什么来解决这个问题?

你们能帮忙吗?非常感谢。

【问题讨论】:

  • 你能发布完整的xml文件吗?
  • 非常感谢,尤其是@NagarjunaReddy。最后,我自己解决问题如下:&lt;ListView android:id="@+id/lstWord" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/bg0" /&gt; ...

标签: android image listview background


【解决方案1】:

用这个代替那个

<LinearLayout 
    xmlns:android= "http://schemas.android.com/apk/res/android"
    android:id="@+id/linearlayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <ImageView
        android:id="@+id/image"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"            
        android:background="@drawable/bg" />
 </Linearlayout>

【讨论】:

  • 非常感谢,但它会删除之前在 main.xml 中设置的所有其他图像。我在帖子中编辑了我的代码以反映整个场景。你还能帮忙吗?
  • @编辑您的总 xml 文件?用full来给出正确的答案。
【解决方案2】:

我发现了问题。只需从主线性布局重力中删除fill_parent。无需像现在一样在 Listview 中设置背景。只需按照我的建议进行更改即可解决您的问题。

android:gravity="bottom|fill_vertical"

【讨论】:

    【解决方案3】:

    我遇到了一个类似的错误,我的背景可绘制对象显示在 eclipse 的图形编辑器中,但在我用于调试的设备上却没有。

    -> 对我来说,它有助于清理图像(我只是在油漆中打开它并保存它),然后我 用新图像覆盖旧图像并将其复制到可绘制文件夹中。

    【讨论】:

      【解决方案4】:

      某些棒棒糖设备无法显示更高分辨率的图像。如果您随机生成背景或使用一组图像将它们加载到背景中,您也可以通过编程手动调整位图的大小

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-03-08
        • 2015-06-21
        • 1970-01-01
        • 2023-02-20
        • 2014-06-28
        • 1970-01-01
        相关资源
        最近更新 更多