mSa*_*del 6 android android-linearlayout android-studio
我创建了一个简单的应用程序并将LinearLayout的背景设置为图像.当我运行它时,不要显示背景图像.我看到这行日志:
W/PackageManager? Failure retrieving resources for vania.backgroundtest: Resource ID #0x0
Run Code Online (Sandbox Code Playgroud)
为什么无法显示背景图片?这是我的布局代码:
<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>
Run Code Online (Sandbox Code Playgroud)
这是我的Java代码:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Run Code Online (Sandbox Code Playgroud)
这很明显:
<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>
Run Code Online (Sandbox Code Playgroud)
我使用了1920*1080(412 KB)的.jpg图像
您应该使用android:background
LinearLayout 的属性
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/myimage"
android:orientation="vertical" >
<!-- More elements -->
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
myimage
中正确的图像在哪里the res/drawable directory
?您可以在文档中找到更多详细信息
归档时间: |
|
查看次数: |
8515 次 |
最近记录: |