颤振行间隔因语言而异

时间:2018-11-02 15:13:17

标签: android textview flutter

如何通过Text小部件强制Flutter遵守给定的行距?

我注意到,根据语言间隔的不同,会导致小部件的高度不可预测。例如,在阿拉伯语中,间隔更大。

我已经比较了Flutter和Android,发现Android的TextView以相同的行距呈现阿拉伯文本(它也会自动将其从右向左呈现,而Flutter则不会,这也是可疑的)。

示例。

颤振 enter image description here 安卓系统 enter image description here

颤振代码

class IneterlineExample extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final style = TextStyle(
        fontSize: 32.0,
      height: 1.0,
        );
    return Scaffold(
        appBar: AppBar(
          title: Text('Interline example'),

        ),
        body: Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Container(
              width: 200.0,
              child: Text("This is a multiline text with English letters",
                  maxLines: 4,
                  overflow: TextOverflow.ellipsis,
                style: style,
              ),
            ),
            Container(
              width: 200.0,
              child: Text("آموزش کامل طرز تهیه پودینگ شکلاتی موز دسر مجلسی",
                  maxLines: 4,
                  overflow: TextOverflow.ellipsis,
                style: style,
              ),
            ),
            Container(
              width: 200.0,
              child: Text("В русском языке интервалы тоже ок Russian",
                  maxLines: 4,
                  overflow: TextOverflow.ellipsis,
                style: style,
              ),
            ),
          ],
        ));
  }
}

Android代码

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

  <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintTop_toTopOf="parent"
      >
    <TextView
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:text="This is a multiline text with English letters"
        android:textSize="32dp"
        android:maxLines="4"
        android:ellipsize="end"
        />
    <TextView
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:text="آموزش کامل طرز تهیه پودینگ شکلاتی موز دسر مجلسی"
        android:textSize="32dp"
        android:maxLines="4"
        android:ellipsize="end"
        />
    <TextView
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:text="В русском языке интервалы тоже ок Russian"
        android:textSize="32dp"
        android:maxLines="4"
        android:ellipsize="end"
        />

  </LinearLayout>


</android.support.constraint.ConstraintLayout>

我要解决的原始问题是将某些文本(语言未知)设置为给定高度。

即我有一些文字,可能很长,还有一个方框,WxH固定大小。我已经计算出,鉴于我的字体大小和height比例,我可以容纳L行文本。因此,我将maxLinesellipsize放在Android应用程序中运行(因为行高是可以预测的),但在Flutter应用程序中却没有。 如果在给定的框上溢出时Flutter文本可以省略,我也可以,但是不确定如何实现。

1 个答案:

答案 0 :(得分:0)