Resource Denial

I created a simple application and set the Background of LinearLayout to the image. when i run it, don't show the background image. I see this log line:

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

Why is it impossible to display a background image? This is my layout code:

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

This is my Java code:

 public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } } 

and this is obvious:

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

I used the .jpg image from 1920 * 1080 (412 KB)

+5
source share
1 answer

You must use the android:background property for LinearLayout

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

Where myimage is the correct image in the res/drawable directory . You can find more detailed information in the documentation.

0
source

Source: https://habr.com/ru/post/1234182/


All Articles