首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >列表中的布局磁贴-颤动

列表中的布局磁贴-颤动
EN

Stack Overflow用户
提问于 2019-05-27 12:44:04
回答 3查看 12.6K关注 0票数 5

当前输出:

预期输出:

代码:

代码语言:javascript
运行
复制
SizedBox(
      width: 380,
      height: 180,
      child: Swiper(
        itemCount: items.length,
        itemBuilder: (context, index) {
          return Column(
            children: <Widget>[
              Expanded(
                child: Card(
                  child: ListTile(
                    title: Text(
                      '${items[index].title}',
                    ),
                    subtitle: Text(
                      '${items[index].body}',
                    ),
                    trailing: Column(
                      children: <Widget>[
                        CircleAvatar(
                          backgroundColor: HexColor("#0087a8"),
                          child: IconButton(
                            icon: Icon(Icons.add),
                      ],
                    ),
                  ),
                ),
              )
            ],
          );
        },
        viewportFraction: 0.8,
        scale: 0.9,
        control: SwiperControl(color: Colors.white),
      ),
    );

我不能创建这样的图标按钮。当我放入填充时,它显示像素溢出。我需要得到右下角的add按钮。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2019-05-27 18:13:46

如前所述,您不应该为此使用ListTile,因为您希望为内容使用的不仅仅是标题、副标题。

我之所以在这里选择Stack而不是Column,是因为它允许你在不同大小的屏幕上安全地使用它,同时确保视图不会溢出。对于Column,它将使用按钮直径作为整个空间来使用(垂直),即使它被限制在框的右侧。

我相信这就是你要找的。

代码语言:javascript
运行
复制
class MyListTile extends StatelessWidget {
  const MyListTile({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 180.0,
      color: const Color(0xff0087a8),
      child: Container(
        padding: const EdgeInsets.all(20.0),
        margin: const EdgeInsets.all(10.0),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.all(Radius.circular(10.0)),
          color: const Color.fromRGBO(19, 12, 117, 1.0),
        ),
        child: Stack(
          children: <Widget>[
            Text(
              'EUR - USD',
              style: Theme.of(context).textTheme.display2.copyWith(
                    color: Colors.white,
                    fontWeight: FontWeight.bold,
                  ),
            ),
            Align(
              alignment: Alignment.centerLeft,
              child: Text(
                'Forex',
                style: TextStyle(color: Colors.white, fontSize: 20.0),
              ),
            ),
            Align(
              alignment: Alignment.bottomRight,
              child: FloatingActionButton(
                backgroundColor: const Color(0xff0087a8),
                onPressed: () {},
                child: Icon(
                  Icons.add,
                  color: Colors.white,
                  size: 50.0,
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}
票数 6
EN

Stack Overflow用户

发布于 2019-05-27 13:46:05

试试这段代码

代码语言:javascript
运行
复制
Container(
        height: 180,
        width: double.infinity,
        child: Card(
          child: Padding(
            padding: const EdgeInsets.all(16.0),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Text(
                      'EUR/USD',
                      style: TextStyle(fontSize: 40),
                    ),
                    Text('FOREX', style: TextStyle(fontSize: 20)),
                  ],
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  children: <Widget>[
                    CircleAvatar(
                        backgroundColor: Colors.blueAccent,
                        child: IconButton(
                          onPressed: () {
                            print('On Pressed');
                          },
                          icon: Icon(Icons.add),
                        )),
                  ],
                )
              ],
            ),
          ),
        ),
      )

票数 3
EN

Stack Overflow用户

发布于 2019-05-27 13:38:46

使用自定义窗口小部件的列表项或列从下面的代码为单一视图。要左对齐和右对齐,您必须将视图放在“align”中,如下所示-

代码语言:javascript
运行
复制
class _ItemsState extends State<Items> {
      @override
      Widget build(BuildContext context) {
        // TODO: implement build
        return Scaffold(
            body: SizedBox(
                width: 380,
                height: 160,
                child: Card(
                    child: ListView.builder(
                        itemCount: 1,
                        itemBuilder: (context, index) {
                          return

                            Padding(padding: EdgeInsets.all(10.0),child:   Column(children: <Widget>[
                              Align(
                                alignment: Alignment.centerLeft,
                                child: Column(children: <Widget>[
                                  Text(
                                    'title',
                                    style: TextStyle(fontSize: 20.0 , fontWeight: FontWeight.bold,),
                                  ),
                                  Text(
                                    'body',
                                    style: TextStyle(fontSize: 14.0),  )
                                ]),
                              ),
                              Align(
                                  alignment: Alignment.centerRight,
                                  child:  CircleAvatar(
                                      maxRadius: 20.0,
                                      backgroundColor: Colors.blueGrey,
                                      child: IconButton(
                                        icon: Icon(Icons.add,
color: Colors.white,),
                                      ))
                              )
                            ]));




                        }))));
      }
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56319781

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档