为什么QuickContactBadge抛出android.view.InflateException?

时间:2014-07-11 12:57:19

标签: android android-layout inflate-exception quickcontactbadge

我正在创建一个可以进行联系人过滤的应用程序,但遗憾的是android.view.InflateException会在启动带有联系人列表的片段时抛出QuickContactBadge,该联系人列表使用大量android.view.InflateException: Binary XML file line #5: Error inflating class android.widget.QuickContactBadge at android.view.LayoutInflater.createView(LayoutInflater.java:626) at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700) at android.view.LayoutInflater.rInflate(LayoutInflater.java:761) at android.view.LayoutInflater.inflate(LayoutInflater.java:498) at android.view.LayoutInflater.inflate(LayoutInflater.java:398) at com.contactexctractor.ContactFragment$ContactsAdapter.newView(ContactFragment.java:127) ... 视图进行单一联系。

在SO上存在类似问题Fragment view inflating error: Resource is not a drawable,提出了几种可能的解决方案。但是,他们没有对此问题作出任何澄清。任何提议的决策仍然存在运行时通胀错误。具体案例请在下面查看。

来自Logcat的

Android运行时错误

public class ContactFragment extends Fragment implements EventSubscriber, LoaderManager.LoaderCallbacks<Cursor>
{
    ...

    private class ContactsAdapter extends CursorAdapter implements SectionIndexer   {
        private LayoutInflater mInflater; 

        /**
         * Instantiates a new Contacts Adapter.
         * @param context A context that has access to the app's layout.
         */
        public ContactsAdapter(Context context) {
            super(context, null, 0);

            // Stores inflater for use later
            mInflater = LayoutInflater.from(context);

            ...
        }

        /**
         * Overrides newView() to inflate the list item views.
         */
        @Override
        public View newView(Context context, Cursor cursor, ViewGroup viewGroup) {
            // Inflates the contact list item layout.
            final View itemLayout = mInflater.inflate(R.layout.contacts_item, viewGroup, false);

            ...
        }

        ...
    }

    ...
}

QuickContactBadge通胀的代码段

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/listPreferredItemHeight" >

    <QuickContactBadge
        android:id="@android:id/contact_icon"
        android:layout_width="?android:attr/listPreferredItemHeight"
        android:layout_height="?android:attr/listPreferredItemHeight"
        android:src="@drawable/ic_contact_picture_holo_light" />

    <TextView
        android:id="@android:id/contact_bio"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@android:id/contact_icon" />

</RelativeLayout>

联系人项目布局XML

{{1}}

0 个答案:

没有答案