【问题标题】:Make scrollable Text inside container in Flutter在 Flutter 中的容器内制作可滚动文本
【发布时间】:2019-08-26 04:38:50
【问题描述】:

我正在尝试在视图中创建可滚动的文本:

// other widgets,

SingleChildScrollView(
  child: Container(
    height: 200,
    child: Text(
      "Long text here which is longer than the container height"))),

// other widgets

文本比其父容器的高度长,但由于某种原因,尽管它被包裹在SingleChildScrollView 中,但文本不可滚动。知道我做错了什么吗?

【问题讨论】:

    标签: dart flutter flutter-layout


    【解决方案1】:

    尝试添加scrollDirection(横向):

    SingleChildScrollView(
    scrollDirection: Axis.horizontal,
      child: Container(
          height: 200,
          child: Text(
              "Long text here which is longer than the container height")))
    

    默认是垂直的。

    或者如果你想拥有你的身高那么你必须改变顺序(SingleChildScrollView里面Container):

    Container(
        height: 200,
        child: SingleChildScrollView(
            child: Text(
                "Long text here which is longer than the container height")))
    

    【讨论】:

    • 谢谢,但我想要垂直。有趣的是,尽管它像您描述的那样水平工作。这不是我想要的。
    • 为什么在这种情况下顺序不同?我想了解
    • 因为 Container 高度是恒定的,并且在屏幕上可见,所以不需要滚动。文本受容器限制,因此如果文本在容器之外,则需要滚动文本。清除? :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-01
    • 1970-01-01
    • 2021-09-02
    • 2021-08-20
    • 1970-01-01
    • 2019-03-24
    相关资源
    最近更新 更多