gpt4 book ai didi

android - 获取资源失败

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:37:30 27 4
gpt4 key购买 nike

我创建了一个简单的应用程序并将 LinearLayout 的背景设置为图像。当我运行它时,不显示背景图像。我看到这行日志:

W/PackageManager﹕ Failure retrieving resources for vania.backgroundtest: Resource ID #0x0

为什么不能显示背景图片?这是我的布局代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="@drawable/backimage"
>
</LinearLayout>

这是我的 Java 代码:

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

这是显而易见的:

  <application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

我使用了 1920*1080 (412 KB) 的 .jpg 图片

最佳答案

您应该使用 LinearLayout 的 android:background 属性

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/myimage"
android:orientation="vertical" >

<!-- More elements -->

</LinearLayout>

其中 myimageres/drawable 目录 中的正确图像。您可以在 documentation 中找到更多详细信息

关于android - 获取资源失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33255590/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com