约束布局不适合屏幕尺寸的问题

时间:2019-08-07 08:10:38

标签: android

enter image description here enter image description here我正在使用约束布局设计带有android studio的android应用,但安装该应用后,android studio ide上的预览不匹配。我张贴了两个图像以显示区别。我不知道问题是从哪里来的,它困扰了我好几天了。

  var url = "http://test/shop/";
  http.get(url).then((res) {
    dynamic list=convert.jsonDecode(res.body);
    setState(() {
      for(var i=0;i<list.length;i++)
        {
          Datmodel_shop dp=new Datmodel_shop();
          dp.id=list[i]['id'];
          dp.title=list[i]['title'];
          dp.imageurl=list[i]['imageurl'];
          dp.date=list[i]['date'];
          dp.des=list[i]['des'];
          dp.price=list[i]['price'];
          dp.view=list[i]['view'];
          listproduct.add(dp);
        }
    });
  });
}

1 个答案:

答案 0 :(得分:1)

您的ConstaintLayout的宽度应为match_parent,并且孩子的宽度必须为0dp(匹配约束),并且其父项Left和Right具有constraints

类似这样的东西:

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

......

        <YourView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

当然,这种布局的容器也必须具有match_parent宽度。