我使用AVD创建了一个7英寸的虚拟设备,屏幕分辨率为2880x1800。我的目标是获得高分辨率的7英寸截图。但是我的应用无法在此设备上加载。该日志表示找不到setContentView(R.layout.my_activity_layout)
处的资源。这是怎么回事?它适用于从normal到xlarge的所有其他设备。有任何想法吗?
这是我的堆栈跟踪。
04-21 21:31:52.513 2380-2380/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.nsouthproductions.mathanimalsaddition, PID: 2380
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nsouthproductions.mathanimalsaddition/com.nsouthproductions.mathanimalsaddition.Main}: android.content.res.Resources$NotFoundException: Resource ID #0x7f040008
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f040008
at android.content.res.Resources.getValue(Resources.java:1233)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2598)
at android.content.res.Resources.getLayout(Resources.java:1049)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:870)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:802)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:916)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:802)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)
at android.app.Activity.setContentView(Activity.java:2144)
at com.nsouthproductions.mathanimalsaddition.Main.onCreate(Main.java:333)
at android.app.Activity.performCreate(Activity.java:5937)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
04-21 21:31:52.740 933-933/? E/EGL_emulation﹕ tid 933: eglCreateSyncKHR(1237): error 0x3004 (EGL_BAD_ATTRIBUTE)
编辑:添加Java和XML,虽然它们非常标准,并且已经证明可以在其他设备上运行。
Java :(错误发生在setContentView()
)
@SuppressLint("NewApi")
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Ensures they resume where left off if hit launcher and game already playing
// If the launcher is trying to create a new instance of Main, this checks to see
// if this is a new instance of the app. If not, close this activity so that the
// one below it (where they left off) is at the top.
if (!isTaskRoot()
&& getIntent().hasCategory(Intent.CATEGORY_LAUNCHER)
&& getIntent().getAction() != null
&& getIntent().getAction().equals(Intent.ACTION_MAIN)) {
finish();
return;
}
Intent intent = getIntent();
if(savedInstanceState != null){
START_IN_PLAY = savedInstanceState.getBoolean(KEY_SHOWING_PLAY, false);
START_IN_PRACTICE = savedInstanceState.getBoolean(KEY_SHOWING_PRACTICE, false);
START_IN_QUIZ = savedInstanceState.getBoolean(KEY_SHOWING_QUIZ, false);
}
context = this;
mDecorView = getWindow().getDecorView();
// call before setContentView to avoid system bars briefly showing
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
System.out.println("checking os version");
if (currentapiVersion >= Build.VERSION_CODES.KITKAT) {
System.out.println("KitKat or newer");
mDecorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
);
} else{
System.out.println("Older than KitKat");
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
setContentView(R.layout.activity_main);
main_layout
资源的 land
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent" tools:context=".Main"
android:id="@+id/area_main_layout">
<!-- The primary full-screen view. This can be replaced with whatever view
is needed to present your content, e.g. VideoView, SurfaceView,
TextureView, etc. -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="2">
<ImageView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:id="@+id/imageView6"
android:src="@drawable/title_math_animals"
android:cropToPadding="false"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:id="@+id/imageView7"
android:src="@drawable/title_addition"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_marginBottom="15dp"
android:layout_weight="3"
android:id="@+id/linlay_main_2">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="200dp"
android:layout_height="60dp"
android:id="@+id/btn_play"
android:layout_centerInParent="true"
android:soundEffectsEnabled="false"
android:background="@drawable/selector_btn_play" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/img_play_text"
android:src="@drawable/text_play"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="200dp"
android:layout_height="60dp"
android:id="@+id/btn_practice"
android:layout_centerInParent="true"
android:soundEffectsEnabled="false"
android:background="@drawable/selector_btn_menu_other" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="28dp"
android:id="@+id/img_practice_text"
android:src="@drawable/text_practice"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="200dp"
android:layout_height="60dp"
android:id="@+id/btn_quiz"
android:layout_centerInParent="true"
android:soundEffectsEnabled="false"
android:background="@drawable/selector_btn_menu_other" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="28dp"
android:id="@+id/img_quiz_text"
android:src="@drawable/text_quiz"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="200dp"
android:layout_height="60dp"
android:id="@+id/btn_animals"
android:layout_centerInParent="true"
android:soundEffectsEnabled="false"
android:background="@drawable/selector_btn_menu_other" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="28dp"
android:id="@+id/img_animals_text"
android:src="@drawable/text_animals"
android:layout_centerInParent="true" />
</RelativeLayout>
</LinearLayout>
<!-- This FrameLayout insets its children based on system windows using
android:fitsSystemWindows. -->
</LinearLayout>
main_layout
资源的 land
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent" tools:context=".Main"
android:id="@+id/area_main_layout">
<!-- The primary full-screen view. This can be replaced with whatever view
is needed to present your content, e.g. VideoView, SurfaceView,
TextureView, etc. -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="2">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView6"
android:src="@drawable/title_math_animals"
android:cropToPadding="false"
android:layout_gravity="center_horizontal"
android:layout_marginTop="7dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="45dp"
android:id="@+id/imageView7"
android:src="@drawable/title_addition"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_marginBottom="10dp"
android:layout_weight="3"
android:id="@+id/linlay_main_2">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="200dp"
android:layout_height="60dp"
android:id="@+id/btn_play"
android:layout_centerInParent="true"
android:soundEffectsEnabled="false"
android:background="@drawable/selector_btn_play" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/img_play_text"
android:src="@drawable/text_play"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="200dp"
android:layout_height="60dp"
android:id="@+id/btn_practice"
android:layout_centerInParent="true"
android:soundEffectsEnabled="false"
android:background="@drawable/selector_btn_menu_other" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="28dp"
android:id="@+id/img_practice_text"
android:src="@drawable/text_practice"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="200dp"
android:layout_height="60dp"
android:id="@+id/btn_quiz"
android:layout_centerInParent="true"
android:soundEffectsEnabled="false"
android:background="@drawable/selector_btn_menu_other" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="28dp"
android:id="@+id/img_quiz_text"
android:src="@drawable/text_quiz"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="200dp"
android:layout_height="60dp"
android:id="@+id/btn_animals"
android:layout_centerInParent="true"
android:soundEffectsEnabled="false"
android:background="@drawable/selector_btn_menu_other" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="28dp"
android:id="@+id/img_animals_text"
android:src="@drawable/text_animals"
android:layout_centerInParent="true" />
</RelativeLayout>
</LinearLayout>
<!-- This FrameLayout insets its children based on system windows using
android:fitsSystemWindows. -->
</LinearLayout>
main_layout
资源的 large_land
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent" tools:context=".Main"
android:id="@+id/area_main_layout">
<!-- The primary full-screen view. This can be replaced with whatever view
is needed to present your content, e.g. VideoView, SurfaceView,
TextureView, etc. -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="3"
android:layout_marginTop="15dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="70dp"
android:id="@+id/imageView6"
android:src="@drawable/title_math_animals"
android:cropToPadding="false"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="70dp"
android:id="@+id/imageView7"
android:src="@drawable/title_addition"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_marginBottom="15dp"
android:layout_weight="6"
android:id="@+id/linlay_main_2"
android:layout_marginTop="10dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="200dp"
android:layout_height="60dp"
android:id="@+id/btn_play"
android:layout_centerInParent="true"
android:soundEffectsEnabled="false"
android:background="@drawable/selector_btn_play" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/img_play_text"
android:src="@drawable/text_play"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="200dp"
android:layout_height="60dp"
android:id="@+id/btn_practice"
android:layout_centerInParent="true"
android:soundEffectsEnabled="false"
android:background="@drawable/selector_btn_menu_other" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="28dp"
android:id="@+id/img_practice_text"
android:src="@drawable/text_practice"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="200dp"
android:layout_height="60dp"
android:id="@+id/btn_quiz"
android:layout_centerInParent="true"
android:soundEffectsEnabled="false"
android:background="@drawable/selector_btn_menu_other" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="28dp"
android:id="@+id/img_quiz_text"
android:src="@drawable/text_quiz"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="200dp"
android:layout_height="60dp"
android:id="@+id/btn_animals"
android:layout_centerInParent="true"
android:soundEffectsEnabled="false"
android:background="@drawable/selector_btn_menu_other" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="28dp"
android:id="@+id/img_animals_text"
android:src="@drawable/text_animals"
android:layout_centerInParent="true" />
</RelativeLayout>
</LinearLayout>
<!-- This FrameLayout insets its children based on system windows using
android:fitsSystemWindows. -->
</LinearLayout>
我无法在没有超出字符限制的情况下发布xlarge-land
。我已经看到所有这些资源在其他设备上成功加载。
答案 0 :(得分:1)
对于任何资源,您始终必须提供默认版本(在非限定资源目录中)作为系统无法确定最合适资源(或者没有与当前配置匹配的资源)的回退。 / p>
有关详细信息,请参阅Providing Resources - Compatibility:
同样,如果您提供基于的不同布局资源 屏幕方向,您应选择一个方向作为默认方向。 例如,而不是在layout-land / for中提供布局资源 横向和布局端口/用于纵向,保留一个作为默认值, 例如布局/横向和布局端口/肖像。