当用作tablayout时,CircleImageView崩溃

时间:2017-08-20 00:52:48

标签: android android-layout android-tablelayout

我有一个如下所示的XML设置。

tab_icon_simple.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:gravity="center"
    android:layout_height="match_parent">

    <ImageView
        android:id="@android:id/icon"
        android:layout_width="@dimen/size_tab_image"
        android:scaleType="fitCenter"
        android:layout_height="@dimen/size_tab_image"/>

// I add this CircleImageView here to conditionally use this to render a profile image. To cover the default imageView icon.

    <de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/profile_icon"
        android:layout_width="@dimen/size_tab_image"
        android:scaleType="fitCenter"
        android:visibility="gone"
        android:layout_height="@dimen/size_tab_image" />
</RelativeLayout>

在我的代码中,我使用上面的XML作为tabLayout的“customView”,

mTabLayout.getTabAt(0).setCustomView(R.layout.tab_icon_simple).setIcon(someIcon1);
mTabLayout.getTabAt(1).setCustomView(R.layout.tab_icon_simple).setIcon(someIcon2);
mTabLayout.getTabAt(2).setCustomView(R.layout.tab_icon_simple).setIcon(someIcon3);

然而,每当代码执行.setCustomView时,我的android立即崩溃。 看起来android无法充气CircleImageView?我该怎么办。

  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.getcharly.android.user/com.getcharly.android.view.activity.main.MainActivity_}: android.view.InflateException: Binary XML file line #13: Error inflating class <unknown>
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2331)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2393)
              at android.app.ActivityThread.access$800(ActivityThread.java:151)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1309)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:135)
              at android.app.ActivityThread.main(ActivityThread.java:5351)
              at java.lang.reflect.Method.invoke(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:372)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
              Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class <unknown>
      at android.view.LayoutInflater.createView(LayoutInflater.java:633)
              at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.createCustomViewInternal(CalligraphyLayoutInflater.java:211)
              at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.access$000(CalligraphyLayoutInflater.java:20)
              at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$PrivateWrapperFactory2.onCreateView(CalligraphyLayoutInflater.java:302)
              at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:177)
              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
              at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
              at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
              at android.support.design.widget.TabLayout$Tab.setCustomView(TabLayout.java:1326)
              at com.my.android.app.view.activity.main.fragment.MainFragment.setupTabLayout(MainFragment.java:277)

1 个答案:

答案 0 :(得分:0)

结果是XML

机器人:scaleType =&#34; fitCenter&#34;

CircleImageView中的

打破了它。