我创建了一个使用此hdodenhof CircleImageview
库的应用。
我的应用程序在Android 7和7.1上工作正常,但它在较低版本中崩溃,如marshmallow / Android 6.如何解决这个问题?我已经阅读了他的GitHub帖子,但它没有解决我的问题,因为人们要求从.xml中删除属性,但我没有使用这些属性。
这是我对CircleImageView的简单实现:
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/civ_requests"
android:layout_width="80sp"
android:layout_height="80sp"
android:layout_margin="10sp"
android:src="@drawable/profilesvg" />
然后是错误:
FATAL EXCEPTION: main
Process: com.milind.locatemymate, PID: 4288
android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class de.hdodenhof.circleimageview.CircleImageView
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.milind.locatemymate.Fragment.Requests$1.onCreateViewHolder(Requests.java:152)
at com.milind.locatemymate.Fragment.Requests$1.onCreateViewHolder(Requests.java:103)
at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6685)
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5869)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5752)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5748)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2232)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1559)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1519)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:614)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3812)
at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:3225)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
at android.view.View.measure(View.java:18788)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1632)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:141)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
朋友片段中的相同错误,继承人更新的xml布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<de.hdodenhof.circleimageview.CircleImageView
android:src="@drawable/profilesvg"
android:id="@+id/civ_friend"
android:layout_width="80dp"
android:layout_height="80dp" />
<LinearLayout
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:padding="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:textStyle="bold"
android:textColor="@color/LightBlack"
android:id="@+id/tv_friendName"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:textColor="@color/LightBlack"
android:layout_marginTop="5dp"
android:id="@+id/tv_friendStatus"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<View
android:layout_marginTop="5dp"
android:background="@color/LightGrey"
android:layout_width="match_parent"
android:layout_height="0.5dp" />
</LinearLayout>
答案 0 :(得分:3)
CHange this:
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/civ_requests"
android:layout_width="80sp"
android:layout_height="80sp"
android:layout_margin="10sp"
android:src="@drawable/profilesvg" />
到此:
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/civ_requests"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_margin="10dp"
android:src="@drawable/profilesvg" />
您假设仅在fontSize中使用SP。对于布局高度和宽度以及边距,单位应为DP。
并确保您的源图像处于可绘制状态而不是drawablev24。
答案 1 :(得分:1)
在我的情况下,我出现此错误,因为我的布局中有adjustViewBounds="true"
。删除它可以解决问题。
答案 2 :(得分:0)
我也遇到相同的问题,宽度和高度为“ dp”。 但是,就我而言,它可以通过将scaleType从fitcenter替换为centerCrop来解决。
答案 3 :(得分:0)
好吧,在检查源代码和实现时,似乎开发人员有意对它们进行了编码,因为我看到在此答案发布之日可能不支持这些编码。
@Override
public void setScaleType(ScaleType scaleType) {
if (scaleType != SCALE_TYPE) {
throw new IllegalArgumentException(String.format("ScaleType %s not supported.", scaleType));
}
}
@Override
public void setAdjustViewBounds(boolean adjustViewBounds) {
if (adjustViewBounds) {
throw new IllegalArgumentException("adjustViewBounds not supported.");
}
}
,唯一受支持的ScaleType是
private static final ScaleType SCALE_TYPE = ScaleType.CENTER_CROP;
因此,在实施修补程序之前,应从XML的CircularImageView属性中删除这些属性。
Lopez Mikhael在https://github.com/lopspower/CircularImageView还有一个替代的CircularImageView库
该库也有一些限制:(至少不支持adjustViewBounds)
限制
默认情况下,ScaleType为 FIT_CENTER
。您也可以使用
CENTER_INSIDE
和 CENTER_CROP
。
不支持启用adjustViewBounds,因为这需要 不支持的ScaleType。