LayoutInflator无法正常工作

时间:2016-01-04 20:20:29

标签: android

当我尝试给布局充气时,我得到了一个例外。据我所知,所有必要的方法都是公开的。为什么会失败,我该如何解决?

AllMediaView类的构造函数:

public AllMediaView(Context context) {
    super(context);
    LayoutInflater layoutInflater = LayoutInflater.from(context);
    View view = layoutInflater.inflate(R.layout.view_all_media, this);
    initViews(context, view);
}

public AllMediaView(Context context, AttributeSet attrs) {
    super(context, attrs);
    LayoutInflater layoutInflater = LayoutInflater.from(context);
    View view = layoutInflater.inflate(R.layout.view_all_media, this);
    initViews(context, view);
}

public AllMediaView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    LayoutInflater layoutInflater = LayoutInflater.from(context);
    View view = layoutInflater.inflate(R.layout.view_all_media, this);
    initViews(context, view);
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public AllMediaView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
    LayoutInflater layoutInflater = LayoutInflater.from(context);
    View view = layoutInflater.inflate(R.layout.view_all_media, this);
    initViews(context, view);
}

SocialMediaView类的构造函数:扩展AllMediaView

public SocialMediaView(Context context) {
    super(context);
    initView(context);
}

public SocialMediaView(Context context, AttributeSet attrs) {
    super(context, attrs);
    initView(context);
}

public SocialMediaView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    initView(context);
}

view_all_media.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:background="@android:color/black">

    <RelativeLayout
        android:id="@+id/all_media_view_iv_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.michaelgarnerdev.allmediaview.AllMediaImageView
            android:id="@+id/all_media_view_iv_photo"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:contentDescription="@string/cd_all_media_view_image"/>
    </RelativeLayout>

    <FrameLayout
        android:id="@+id/all_media_view_rl_video_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/black">

        <com.michaelgarnerdev.allmediaview.AllMediaVideoView
            android:id="@+id/all_media_view_cvv_video"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"/>

        <com.michaelgarnerdev.allmediaview.AllMediaMediaController
            android:id="@+id/all_media_view_cmc_controls"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|center_horizontal"
            android:elevation="4dp"/>

        <ProgressBar
            android:id="@+id/all_media_view_video_loading_progress"
            android:layout_width="50dip"
            android:layout_height="50dip"
            android:layout_gravity="center"
            android:visibility="gone"/>
    </FrameLayout>
</FrameLayout>

堆栈追踪:

01-04 12:21:38.152 14860-14860/com.currantcreekoutfitters.camophoto E/AndroidRuntime: FATAL EXCEPTION: main
 Process: com.currantcreekoutfitters.camophoto, PID: 14860
 android.view.InflateException: Binary XML file line #36: Error inflating class com.currantcreekoutfitters.widget.SocialMediaView
 at android.view.LayoutInflater.createView(LayoutInflater.java:626)
 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
 at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
 at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
 at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
 at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
 at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
 at com.currantcreekoutfitters.utility.FontUtil.inflate(FontUtil.java:26)
 at com.currantcreekoutfitters.adapters.CoPhotoAdapter.onCreateViewHolder(CoPhotoAdapter.java:46)
 at com.currantcreekoutfitters.adapters.CoPhotoAdapter.onCreateViewHolder(CoPhotoAdapter.java:25)
 at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5228)
 at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4453)
 at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4363)
 at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1961)
 at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1370)
 at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1333)
 at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:562)
 at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2900)
 at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3071)
 at android.view.View.layout(View.java:15598)
 at android.view.ViewGroup.layout(ViewGroup.java:4880)
 at android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:584)
 at android.view.View.layout(View.java:15598)
 at android.view.ViewGroup.layout(ViewGroup.java:4880)
 at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
 at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
 at android.view.View.layout(View.java:15598)
 at android.view.ViewGroup.layout(ViewGroup.java:4880)
 at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055)
 at android.view.View.layout(View.java:15598)
 at android.view.ViewGroup.layout(ViewGroup.java:4880)
 at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1043)
 at android.view.View.layout(View.java:15598)
 at android.view.ViewGroup.layout(ViewGroup.java:4880)
 at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
 at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
 at android.view.View.layout(View.java:15598)
 at android.view.ViewGroup.layout(ViewGroup.java:4880)
 at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
 at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
 at android.widget.LinearLayout.onLayout(LinearLayout.java:1440)
 at android.view.View.layout(View.java:15598)
 at android.view.ViewGroup.layout(ViewGroup.java:4880)
 at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
 at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
 at android.view.View.layout(View.java:15598)
 at android.view.ViewGroup.layout(ViewGroup.java:4880)
 at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
 at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
 at android.widget.LinearLayout.onLayout(LinearLayout.java:1440)
 at android.view.View.layout(View.java:15598)
 at android.view.ViewGroup.layout(ViewGroup.java:4880)
 at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
 at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
 at android.view.View.layout(View.java:15598)
 at android.view.ViewGroup.layout(ViewGroup.java:4880)
 at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2350)
 at android.view.ViewRootImpl.performTraversals(ViewR

2 个答案:

答案 0 :(得分:0)

您是否可以共享您正在膨胀的布局的XML文件? 我曾经有过同样无法解释的错误,当我使用&#34;查看&#34;而不是&#34;查看&#34;在布局中。

答案 1 :(得分:0)

找到它。

<com.michaelgarnerdev.allmediaview.AllMediaVideoView

项目中不再存在。只需要更改参考。