由于背景图片

时间:2016-09-27 05:04:36

标签: android xml nexus-4

我已将背景图像设置为根布局。这适用于nexus 5(5.0.1)和nexus 5x(6.0.1)。 但是在nexus 4(4.4.4)应用程序崩溃并发出以下错误

  

android.view.InflateException:二进制XML文件行#19:错误   膨胀班                                                                                  在android.view.LayoutInflater.createView(LayoutInflater.java:620)                                                                                  在   android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)                                                                                  在android.view.LayoutInflater.rInflate(LayoutInflater.java:755)                                                                                  在android.view.LayoutInflater.inflate(LayoutInflater.java:492)                                                                                  在android.view.LayoutInflater.inflate(LayoutInflater.java:397)                                                                                  在   com.mobifilia.monitormymortgage.Fragments.HelpScreenFirstFragment.onCreateView(HelpScreenFirstFragment.java:38)                                                                                  在   android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)                                                                                  在   android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)                                                                                  在   android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)                                                                                  在   android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742)                                                                                  在   android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)                                                                                  在   android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)                                                                                  在   android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)                                                                                  在android.support.v4.view.ViewPager.populate(ViewPager.java:1177)                                                                                  在android.support.v4.view.ViewPager.populate(ViewPager.java:1025)                                                                                  在android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1545)                                                                                  在android.view.View.measure(View.java:16497)                                                                                  在   android.widget.RelativeLayout.measureChildHorizo​​ntal(RelativeLayout.java:719)                                                                                  在android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)                                                                                  在android.view.View.measure(View.java:16497)                                                                                  在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)                                                                                  在   android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)                                                                                  在android.widget.LinearLayout.measureVertical(LinearLayout.java:695)                                                                                  在android.widget.LinearLayout.onMeasure(LinearLayout.java:588)                                                                                  在android.view.View.measure(View.java:16497)                                                                                  在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)                                                                                  在   android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:668)                                                                                  在   android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:735)                                                                                  在android.view.View.measure(View.java:16497)                                                                                  在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)                                                                                  在android.widget.FrameLayout.onMeasure(FrameLayout.java:310)                                                                                  在   android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)                                                                                  在android.view.View.measure(View.java:16497)                                                                                  在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)                                                                                  在   android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)                                                                                  在android.widget.LinearLayout.measureVertical(LinearLayout.java:695)                                                                                  在android.widget.LinearLayout.onMeasure(LinearLayout.java:588)                                                                                  在android.view.View.measure(View.java:16497)                                                                                  在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)                                                                                  在android.widget.FrameLayout.onMeasure(FrameLayout.java:310)                                                                                  在android.view.View.measure(View.java:16497)                                                                                  在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)                                                                                  在   android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)                                                                                  在android.widget.LinearLayout.measureVertical(LinearLayout.java:695)                                                                                  在android.widget.LinearLayout.onMeasure(LinearLayout.java:588)                                                                                  在android.view.View.measure(View.java:16497)                                                                                  在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)                                                                                  在android.widget.FrameLayout.onMeasure(FrameLayout.java:310)                                                                                  在   com.android.internal.policy.impl.PhoneWindow $ DecorView.onMeasure(PhoneWindow.java:2291)                                                                                  在android.view.View.measure(View.java:16497)                                                                                  在android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1912)                                                                                  在android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1109)                                                                                  在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1291)                                                                                  在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996)

这是xml文件。

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/backgraound">


        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="none">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
       // other view
     </LinearLayout>
        </ScrollView>
    </RelativeLayout>

如果我从xml中删除背景图像,这也适用于nexus 4。 我该如何解决这个问题?提前致谢

2 个答案:

答案 0 :(得分:2)

您可能已将图片放入 drawable-v21 文件夹中,该文件夹指的是Api 21级及以上。这些文件夹特定于 Lolipop 发布Lolipop 版本。这就是为什么它不在Kitkat或更低版本中工作的原因。将您的图像放在 drawable 文件夹中,以便所有api版本都可以访问它。 很高兴帮忙......

答案 1 :(得分:1)

只需将图像放入drawable文件夹即可。 drawable -v21适用于Android版本&gt; 19。因为如果这在android 4.4(api 19)中,它无法获取图像,而且可能会抛出错误