Android:android.view.InflateException:二进制XML文件第0行:错误放大了类Button

时间:2019-02-15 11:18:56

标签: java android android-layout

我正在跟踪异常

  

02-15 15:54:01.860 15393-15393 / com.neml.auctions E / AndroidRuntime:   致命异常:主要       程序:com.neml.auctions,PID:15393       android.view.InflateException:二进制XML文件第0行:膨胀类按钮时出错           在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:719)           在android.view.LayoutInflater.rInflate(LayoutInflater.java:761)           在android.view.LayoutInflater.rInflate(LayoutInflater.java:769)           在android.view.LayoutInflater.rInflate(LayoutInflater.java:769)           在android.view.LayoutInflater.inflate(LayoutInflater.java:498)           在android.view.LayoutInflater.inflate(LayoutInflater.java:398)           在android.view.LayoutInflater.inflate(LayoutInflater.java:354)           在com.neml.auctions.fragments.AuctionDetailsFragment.onCreateView(AuctionDetailsFragment.java:83)           在android.support.v4.app.Fragment.performCreateView(Fragment.java:2239)           在android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1332)           在android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1574)           在android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1641)           在android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:794)           在android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2415)           在android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2200)           在android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2153)           在android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2034)           在android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:651)           在android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:166)           在android.support.v4.view.ViewPager.populate(ViewPager.java:1239)           在android.support.v4.view.ViewPager.populate(ViewPager.java:1087)           在android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1613)           在android.view.View.measure(View.java:17327)           在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5363)           在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)           在android.widget.LinearLayout.measureVertical(LinearLayout.java:695)           在android.widget.LinearLayout.onMeasure(LinearLayout.java:588)           在android.view.View.measure(View.java:17327)           在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5363)           在android.widget.FrameLayout.onMeasure(FrameLayout.java:310)           在android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)           在android.view.View.measure(View.java:17327)           在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5363)           在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)           在android.widget.LinearLayout.measureVertical(LinearLayout.java:695)           在android.widget.LinearLayout.onMeasure(LinearLayout.java:588)           在android.view.View.measure(View.java:17327)           在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5363)           在android.widget.FrameLayout.onMeasure(FrameLayout.java:310)           在android.view.View.measure(View.java:17327)           在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5363)           在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)           在android.widget.LinearLayout.measureVertical(LinearLayout.java:695)           在android.widget.LinearLayout.onMeasure(LinearLayout.java:588)           在android.view.View.measure(View.java:17327)           在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5363)           在android.widget.FrameLayout.onMeasure(FrameLayout.java:310)           在com.android.internal.policy.impl.PhoneWindow $ DecorView.onMeasure(PhoneWindow.java:2548)           在android.view.View.measure(View.java:17327)           在android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2277)           在android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1391)           在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1590)           在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1249)           在android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:6529)         在android.vi

这是我正在使用的布局的代码

<Button
                android:id="@+id/bt_fragment_auc_details_sessions"
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:layout_gravity="right"
                android:layout_marginTop="@dimen/layout_top_bottom_margin"
                android:background="@drawable/button_session_selector"
                android:drawableLeft="@drawable/ic_session"
                android:drawablePadding="@dimen/edittext_padding"
                android:text="@string/sessions"
                android:textColor="@color/white" />


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="@dimen/layout_top_bottom_margin"
                android:orientation="vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/layout_top_bottom_margin"
                    android:layout_marginBottom="@dimen/layout_top_bottom_margin"
                    android:paddingTop="@dimen/textview_padding"
                    android:text="@string/contract_details"
                    android:textColor="@color/colorPrimary"
                    android:textSize="@dimen/fragment_auction_floor_qty_value_text_size" />

                <ListView
                    android:id="@+id/lv_fragment_auction_details_contract_details"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />
            </LinearLayout>

button_session_selector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/button_session_bg_pressed" android:state_pressed="true"/>
    <item android:drawable="@drawable/button_session_bg_pressed" android:state_focused="true"/>
    <item android:drawable="@drawable/button_session_bg"/>
</selector>

button_session_bg_pressed.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle">
        <solid
            android:color="@color/colorPrimaryDark"/>
        <corners android:radius="@dimen/card_radius"
            />
        <padding

            android:left="@dimen/edittext_padding"
            android:right="@dimen/edittext_padding"
            />
    </shape>
</item>
</layer-list>

button_session_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/colorAccent" />
            <corners android:radius="@dimen/card_radius" />
            <padding
                android:left="@dimen/edittext_padding"
                android:right="@dimen/edittext_padding"
                >
            </padding>
        </shape>
    </item>
</layer-list>

删除或添加<?xml version="1.0" encoding="utf-8"?>并没有帮助。 任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

尝试将片段类内部的按钮视图从onCreateView移到onViewCreated或onStart。

希望这会有所帮助:)