Как я могу исправить ошибку: Ошибка надувания класса android.widget.ProgressBar, вызванная файлом XML - PullRequest
0 голосов
/ 17 июня 2019

В моем фрагменте я хочу вставить Relative-Layout, включая мой собственный 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>

Error

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 голосов
/ 17 июня 2019

Проблема: ...xml(24) Я не знаю, о чем 24, но это причина того, что он не работает ... Просто создайте новый рисуемый файл и передайте содержимое.

Но возьмитепозаботьтесь о файле hase no (24) сзади.

Я не знаю об этом, но это может быть решением для некоторых других вопросов, связанных с этой ошибкой.

...