扩展类de.hdodenhof.circleimageview.CircleImageView时出错

问题描述 投票:0回答:2

不知道为什么它不起作用。给出here的答案不适用于我,因为我的尺寸已经在dp

这是我的活动

hits_item.xml:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:algolia="http://schemas.android.com/apk/res-auto">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<de.hdodenhof.circleimageview.CircleImageView
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/user_image"
    android:layout_width="100dp"
    android:layout_height="100dp"
    app:civ_border_width="4dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="20dp"
    app:civ_border_color="#c42f92"
    android:scaleType="fitCenter"
    algolia:attribute='@{"image"}'/>
<TextView
    android:id="@+id/user_name"
    android:paddingTop="20dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    algolia:attribute='@{"username"}'
    algolia:highlighted='@{true}'/>
</LinearLayout>
</layout>
android android-layout android-xml algolia
2个回答
2
投票

此行会使您的应用崩溃

android:scaleType="fitCenter"

来自CircleImageView github。

限制

ScaleType始终是CENTER_CROP,如果您尝试更改它,您将获得异常。这是(目前)设计,因为它对于个人资料图像非常好。

在logcat中,您将看到此错误。

Caused by: java.lang.IllegalArgumentException: ScaleType FIT_CENTER not supported.

解决方案:从布局xml文件中删除android:scaleType="fitCenter"


0
投票

这是因为你错误地将标签添加为View xml。这是错的:

<!-- Below line is in a wrong place and wrong tag. -->
<layout xmlns:algolia="http://schemas.android.com/apk/res-auto">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

   ...
</LinearLayout>

它应该是:

<LinearLayout 
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:algolia="http://schemas.android.com/apk/res-auto"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   android:orientation="horizontal"
   android:layout_width="match_parent"
   android:layout_height="match_parent">

   ...

</LinearLayout>
© www.soinside.com 2019 - 2024. All rights reserved.