我正在尝试使用第三方 AutuResizeTextView 库,但不幸的是它无法正常工作。在我使用它的第一种情况下,我正在更改 AutoResize View 内的文本,每当我设置新文本时, View 的大小就会变得小得多。第二种情况是我有一个自动调整大小 View 列表,但只有一些文本可以正确调整大小。所有这些都是使用 XML 完成的。
链接到库:https://github.com/AndroidDeveloperLB/AutoFitTextView
第一种情况:
<?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:layout_gravity="center" >
<com.lb.auto_fit_textview.AutoResizeTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:ellipsize="none"
android:maxLines="1"
android:textColor="@color/white"
android:id="@+id/title"
android:textSize="24sp" />
</LinearLayout>
第二种情况:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="20dp" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/place_info_container"
android:layout_centerVertical="true">
<com.lb.auto_fit_textview.AutoResizeTextView
android:id="@+id/place_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="24sp"
android:maxLines="1"/>
<com.lb.auto_fit_textview.AutoResizeTextView
android:id="@+id/place_type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="14sp"
android:layout_below="@id/place_name"
android:maxLines="1"/>
</RelativeLayout>
</RelativeLayout>
感谢您的帮助:)
最佳答案
据我所知this custom view 工作得非常好 - 它与您使用的库具有相同的功能。此外,还有很多自动调整 TextView 大小的实现。如果您需要结果并且并不真正关心使用哪种解决方案,也许可以尝试使用另一种解决方案。
此外,“Grantland”实现与 ListView 配合良好(或者几个月前就有效)。
关于android - AutoResizeTextView 未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25723119/