简体   繁体   English

如何将小部件放在两个小部件的中心和顶部?

[英]How to put widget in the center and top of two widgets?

I am designing a widget where, I want to put widget in the center of two rectangular container.我正在设计一个小部件,我想将小部件放在两个矩形容器的中心。 My idea is that when I click on it, center widget becomes visible.我的想法是,当我单击它时,中心小部件变得可见。 It looks like this.它看起来像这样。

在此处输入图像描述

What I wanted to do is that clicking on one grey container or both, this purple widget becomes visible, clicking again, it would disappear.我想要做的是单击一个灰色容器或两者,这个紫色小部件变得可见,再次单击它会消失。 This is my code below.这是我下面的代码。

 Stack(
            alignment: Alignment.center,
            children: [
              Container(
                  width: 70,
                  height: 40,
                color: Colors.indigo,
              ),
              Container(
                width: 100,
                height: 70,
                child: Column(
                  children: [
                    Container(
                      width: 100,
                      height: 30,
                      decoration: BoxDecoration(
                        color: Colors.grey,
                      ),
                    ),
                    SizedBox(height: 10,),
                    Container(
                      width: 100,
                      height: 30,
                      decoration: BoxDecoration(
                        color: Colors.grey,
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),

However, with this the widget hides behind two widgets like this.但是,有了这个小部件隐藏在两个像这样的小部件后面。 在此处输入图像描述

Anybody can help me with its positioning?有人可以帮我定位吗?

Here is my answer.这是我的答案。

Stack(
                alignment: Alignment.center,
                children: [
                  Container(
                    width: 100,
                    height: 70,
                    child: Column(
                      children: [
                        Container(
                          width: 100,
                          height: 30,
                          decoration: BoxDecoration(
                            color: Colors.grey,
                          ),
                        ),
                        SizedBox(height: 10,),
                        Container(
                          width: 100,
                          height: 30,
                          decoration: BoxDecoration(
                            color: Colors.grey,
                          ),
                        ),
                      ],
                    ),
                  ),
                  Container(
                    width: 70,
                    height: 40,
                    color: Colors.indigo,
                  ),
                ],
              ),

Just replace the widgets只需更换小部件

 Stack(
        alignment: Alignment.center,
        children: [
          Container(
            width: 100,
            height: 70,
            child: Column(
              children: [
                Container(
                  width: 100,
                  height: 30,
                  decoration: BoxDecoration(
                    color: Colors.grey,
                  ),
                ),
                SizedBox(height: 10,),
                Container(
                  width: 100,
                  height: 30,
                  decoration: BoxDecoration(
                    color: Colors.grey,
                  ),
                ),

          Container(
              width: 70,
              height: 40,
            color: Colors.indigo,
          ),
              ],
            ),
          ),
        ],
      ),

like stack ;)像堆栈;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将2个子小部件中的一个子小部件居中 - How to center one of the child widget out of 2 child widgets 如何将图片放在中心的背景图像之上? - How to put a picture on top of a background image in the center? 如何将imageview放在自定义对话框的顶部? - How to put imageview on center top of custom dialog? 如何使用两个按钮将布局集中在中心和顶部 - how to centralize layout in center and top with two buttons Android将小部件置于所有其他小部件之上 - Android bring a widget on top of all other widgets android-如果我将两个小部件彼此叠放然后触摸它们,会发生什么? - android-what will happen if I put two widgets on top of each other and then touch them? 如何将按钮放在 android.support.design.widget.AppBarLayout 之上? - how to put button on top of android.support.design.widget.AppBarLayout? 将两个视图放在屏幕中央 - Put two views in the center of the screen 我希望第二个小部件(容器)与左侧对齐,但它与中心对齐。 如何将它与其他小部件的左侧对齐? - I want the second widget(container) to be aligned to the left but it's aligned to the center. How can I align it to the left along other widgets? 如何在 DraggableScrollableSheet 小部件中固定前两个最顶部的小部件? - How can I pin first two top most widget in DraggableScrollableSheet widget?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM