Android – layout baseline to baseline with auto resizing constraints

I'm trying to align two text views according to the baseline and use autosize for textization. This is a simplified code example. The first textview has a large size, so textize auto is set to some large values. The second textview is smaller than the first textview, so it has a small automatically determined text size

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">

<TextView
    android:id="@+id/text1"
    android:layout_width="200dp"
    android:layout_height="100dp"
    android:text="text1"
    android:maxLines="1"
    android:autoSizeTextType="uniform"
    android:autoSizeMaxTextSize="200sp"
    android:autoSizeMinTextSize="2sp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toLeftOf="@+id/text2"
    app:layout_constraintTop_toTopOf="parent"/>

<TextView
    android:id="@+id/text2"
    android:layout_width="50dp"
    android:layout_height="20dp"
    android:text="text2"
    android:maxLines="1"
    android:autoSizeTextType="uniform"
    android:autoSizeMaxTextSize="200sp"
    android:autoSizeMinTextSize="2sp"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintLeft_toRightOf="@+id/text1"
    app:layout_constraintBaseline_toBaselineOf="@id/text1"/>
</android.support.constraint.ConstraintLayout>
@H_403_9@

result of example code

问题是,当我使用autoSizeTextType时,layout_constraintBaseline_toBaselineOf似乎停止工作

如果有人能指出正确的方向,那就太好了.我理解错误如何使用constraintlayout?或者只是baseline_tobaseline不能用于自动调整大小?

解决方法:

我正在使用黑客来解决这个问题.

幸运的是,在我的情况下,我有两个字,所以最后我想出了类似的东西:

private fun getCorrectTextValue(value: Number): SpannableString {
    val currency = getString(R.string.common_currency)
    val formatter = NumberFormat.getInstance(Locale.getDefault())
    val ss = SpannableString("${formatter.format(value)} $currency")
    ss.setSpan(AbsoluteSizeSpan(resources.getDimensionPixelSize(R.dimen.max_text_size)), value.toString().length, value.toString().length + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
    return ss
}
@H_403_9@

它对我有

可能你可以使用SpannableString添加一个空格字符,并使用以下内容设置它的高度:

ss.setSpan(AbsoluteSizeSpan(resources.getDimensionPixelSize(R.dimen.max_text_size)), value.toString().length, value.toString().length + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
@H_403_9@

          

总结

以上是编程之家为你收集整理的android – 使用自动调整大小的约束布局基线到基线全部内容,希望文章能够帮你解决android – 使用自动调整大小的约束布局基线到基线所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
喜欢与人分享编程技术与工作经验,欢迎加入编程之家官方交流群!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>