如何解决小屏设备中因布局边距导致AppCompatTextView被裁剪问题?
小屏设备下AppCompatTextView文字裁剪的最优解决方案?
我使用ConstraintLayout布局,其中包含一个AppCompatTextView,并设置了app:autoSizeTextType="uniform"属性让文字根据屏幕尺寸自动调整大小(因此控件宽高设为0dp)。为适配5英寸和6英寸设备的显示效果,我添加了layout_marginTop和layout_marginBottom来缩小控件布局范围,以此让文字尺寸适配。但在3.7英寸或4英寸的小屏设备上,由于边距占比过大,导致AppCompatTextView中的文字无法完全显示而被裁剪。
相关布局代码如下:
<androidx.appcompat.widget.AppCompatTextView android:id="@+id/tev" android:layout_width="0dp" android:layout_height="0dp" android:gravity="start" android:text="@string/strng" app:autoSizeTextType="uniform" app:layout_constraintBottom_toBottomOf="@id/dr2" app:layout_constraintEnd_toStartOf="@id/dlo" app:layout_constraintStart_toEndOf="@id/miu" app:layout_constraintTop_toTopOf="@id/cra" android:layout_marginTop="12dp" android:layout_marginBottom="12dp" />
文字裁剪效果如图:
我了解到可设置app:autoSizeMinTextSize为较小dp值来解决,但想确认:根据屏幕尺寸设置动态布局边距是否是更优方案?
内容的提问来源于stack exchange,提问作者sacacorchos
相关产品推荐
相关产品推荐

