如何修复错误:XML文件导致类android.widget.ProgressBar膨胀错误

时间:2019-06-17 09:27:51

标签: android fragment progress-bar

在我的片段中,我想粘贴一个相对布局,包括我的自定义progrssBar。 加载android:progressDrawable="@drawable/loadingbackground"时,总是出现相同的错误: android.view.InflateException: Binary XML file line #30: Binary XML file line #30: Error inflating class android.widget.ProgressBar

通过调试,我发现这确实是loadingbackground.xml (V24)导致错误的原因。

片段

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/Fragment1_Driver1"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="1000dp"
    android:layout_height="300dp"
    android:background="#E91E63"


    tools:context=".cf_Fragment_MainDriver1">

    <!-- TODO: Update blank fragment layout -->
    <TextView
        android:id="@+id/tv_MainDriver1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_blank_fragment"
        android:textSize="24dp" />

    <RelativeLayout
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="50dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <ProgressBar
            android:id="@+id/pb_Driver1_Main_1"
            style="?android:progressBarStyleHorizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@id/tv_Title_Driver1_Main_1"
            android:layout_alignParentTop="true"
            android:layout_alignParentBottom="false"
            android:progress="100"
            android:progressDrawable="@drawable/loadingbackground"
            android:progressTintMode="src_atop"
            android:rotation="270"
            android:secondaryProgress="100"
            android:secondaryProgressTint="#7E00E5FF"
            android:secondaryProgressTintMode="src_in"
            android:visibility="visible" />

        <TextView
            android:id="@+id/tv_Time_Driver1_Main_1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/tv_Title_Driver1_Main_1"
            android:layout_alignParentStart="false"
            android:layout_alignParentTop="false"
            android:layout_alignParentEnd="false"
            android:layout_alignParentBottom="false"
            android:layout_centerInParent="false"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="60dp"
            android:hint="1h 10min"
            android:textColor="#FFFFFF"
            android:textColorHint="#FFFFFF"
            android:textSize="24sp"
            android:textStyle="bold"
            tools:text="1h 10 min" />

        <TextView
            android:id="@+id/tv_Title_Driver1_Main_1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:gravity="center"
            android:textColor="#FFFFFF"
            android:textColorHint="#FFFFFF"
            android:textSize="30dp"
            android:textStyle="bold"
            tools:text="Lenkzeit" />
    </RelativeLayout>




</FrameLayout>

loadingbackground

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <item android:id="@android:id/secondaryProgress">
        <shape
            android:innerRadius="60dp"
            android:shape="ring"
            android:thickness="10dp"
            android:useLevel="false"
            >
        </shape>
    </item>

    <item android:id="@android:id/progress">
        <shape
            android:innerRadius="60dp"
            android:shape="ring"
            android:thickness="15dp"
            android:useLevel="false">
            <gradient
                android:startColor="#0bd92d"
                android:centerColor="#d9e910"
                android:endColor="#f91619"
                android:type="sweep"
                android:angle="270"/>
        </shape>
    </item>

</layer-list>

错误

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.fragmentmanagermain, PID: 26845
    android.view.InflateException: Binary XML file line #23: Binary XML file line #23: Error inflating class android.widget.ProgressBar
        at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
        at com.example.fragmentmanagermain.cf_Fragment_MainDriver1.onCreateView(cf_Fragment_MainDriver1.java:31)
        at android.support.v4.app.Fragment.performCreateView(Fragment.java:2439)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
        at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
        at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:802)
        at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
        at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
        at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
        at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2243)
        at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:654)
        at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:168)
        at android.support.v4.view.ViewPager.populate(ViewPager.java:1244)
        at android.support.v4.view.ViewPager.populate(ViewPager.java:1092)
        at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1622)
        at android.view.View.measure(View.java:18880)
        at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:716)
        at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:462)
        at android.view.View.measure(View.java:18880)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5952)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
        at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
        at android.view.View.measure(View.java:18880)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5952)
        at android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:401)
        at android.view.View.measure(View.java:18880)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5952)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
        at android.view.View.measure(View.java:18880)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5952)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
        at android.view.View.measure(View.java:18880)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5952)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
        at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2650)
        at android.view.View.measure(View.java:18880)
        at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2104)
        at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1220)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1456)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1111)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6017)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
        at android.view.Choreographer.doCallbacks(Choreographer.java:670)
        at android.view.Choreographer.doFrame(Choreographer.java:606)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:224)
        at android.app.ActivityThread.main(ActivityThread.java:5526)
        at java.lang.reflect.Method

更新

即使loadingbackground.xml为空,也会出现错误。 这是片段中禁止的吗?

1 个答案:

答案 0 :(得分:0)

问题:...xml(24) 我不知道24是什么意思,但这就是它不起作用的原因... 只需创建一个新的可绘制文件并传递内容即可。

但是请注意文件的背面没有(24)。

我对此一无所知,但这可能是与该错误有关的其他一些问题的解决方案。