Android 颤振中的相对弹性等效

Android 颤振中的相对弹性等效,android,dart,flutter,android-relativelayout,Android,Dart,Flutter,Android Relativelayout,有没有一种方法可以实现类似于RelativeLayout在Android上所做的事情 特别是,我正在寻找类似于centerInParent、下面的layout:、上面的layout:、和alignParentLeft 有关RelativeLayout的更多参考信息: 编辑:下面是一个依赖于RelativeLayout 因此,在上图的顶部,“豆腐歌”文本在一个RelativeLayout内对齐为centerInParent。而另外两个是alignParentLeft和alignParentRig

有没有一种方法可以实现类似于
RelativeLayout
在Android上所做的事情

特别是,我正在寻找类似于
centerInParent
、下面的
layout:
、上面的
layout:
、和
alignParentLeft

有关RelativeLayout的更多参考信息:

编辑:下面是一个依赖于
RelativeLayout

因此,在上图的顶部,“豆腐歌”文本在一个
RelativeLayout
内对齐为
centerInParent
。而另外两个是
alignParentLeft
alignParentRight


在火图标所在的每个单元格上,其底部的喜欢数围绕火焰图标的中心对齐。此外,每个单元上的顶部和底部标题分别与图像化身的右侧以及顶部和底部对齐

颤振布局通常使用、和小部件树构建。这些小部件采用构造函数参数,这些参数指定子部件相对于父部件的布局规则,您还可以通过将子部件包装在、或小部件中来影响单个子部件的布局

也可以使用创建复杂的布局。这是如何在内部实现的,在应用程序中如何使用它的示例出现在。您还可以使用或,或沿图层向下延伸,如中所示。像这样手动进行布局需要做更多的工作,并且在一些特殊情况下会产生更多的错误,所以如果可以的话,我会尝试使用高级布局原语

要回答您的具体问题:

  • 使用
    前导
    尾随
    参数定位应用程序栏元素。如果要改用
    ,请使用
    mainAxisAlignment.spaceBetween的
    mainAxisAlignment
  • 使用带有
    crossAxisAlignment的
    crossAxisAlignment的
  • 使用带有
    mainAxisAlignment的
    mainAxisAlignment的
    mainAxisAlignment
    。空格介于
    之间以定位顶部和底部标题。(你应该考虑用它来列出列表瓦片,但是如果你这样做,你将失去对精确定位的控制。)
下面是实现您提供的设计的代码段。在本例中,我使用了确定歌曲平铺的高度,但您可以通过将其硬编码为固定高度来提高性能

导入“包装:颤振/材料.省道”;
void main(){
runApp(新的MyApp());
}
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回新材料PP(
标题:“颤振演示”,
主题:新主题数据(
亮度:亮度。暗,
PrimaryColor亮度:亮度。暗,
),
主页:新的主屏幕(),
debugShowCheckedModeBanner:false,
);
}
}
类Song扩展了无状态小部件{
const-Song({this.title,this.author,this.likes});
最后的字符串标题;
最终字符串作者;
最终的int-likes;
@凌驾
小部件构建(构建上下文){
text主题text主题=主题
.of(上下文)
.文本主题;
退回新货柜(
边距:常量边集。对称(水平:10.0,垂直:5.0),
填充:常量边集。对称(水平:15.0,垂直:10.0),
装饰:新盒子装饰(
颜色:颜色。灰色。阴影200。不透明度(0.3),
边界半径:新边界半径。圆形(5.0),
),
孩子:新的内在精神(
孩子:新的一排(
crossAxisAlignment:crossAxisAlignment.stretch,
儿童:[
新容器(
边距:仅限常量边集(顶部:4.0,底部:4.0,右侧:10.0),
孩子:新CircleAvatar(
背景图片:新网络图片(
'http://thecatapi.com/api/images/get?format=src'
“&size=small&type=jpg#${title.hashCode}”
),
半径:20.0,
),
),
新扩展(
子容器:新容器(
子:新列(
crossAxisAlignment:crossAxisAlignment.start,
mainAxisAlignment:mainAxisAlignment.spaceBetween,
儿童:[
新文本(标题、样式:textTheme.subhead),
新文本(作者,样式:textTheme.caption),
],
),
),
),
新容器(
边距:新边集。对称(水平:5.0),
孩子:新墨水井(
子:新图标(Icons.play_箭头,大小:40.0),
onTap:(){
//待办事项(实施)
},
),
),
新容器(
边距:新边集。对称(水平:5.0),
孩子:新墨水井(
子:新列(
mainAxisAlignment:mainAxisAlignment.center,
crossAxisAlignment:crossAxisAlignment.center,
儿童:[
新图标(Icons.favorite,大小:25.0),
新文本(“${likes???”}”),
],
),
onTap:(){
//待办事项(实施)
},
),
),
],
),
),
);
}
}
类提要扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回新的ListView(
儿童:[
新歌(标题:'Trapadelic lobo',作者:'lillobobeats',喜欢:4),
新歌(标题:“不同”,作者:“younglowkey”,喜欢:23),
新歌(标题:“未来”,作者:“younglowkey”,喜欢:2),
新歌(标题:'ASAP',作者:'tha_producer808',喜欢:13),
新的
import 'package:flutter/material.dart';

void main() {
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Demo',
      theme: new ThemeData(
        brightness: Brightness.dark,
        primaryColorBrightness: Brightness.dark,
      ),
      home: new HomeScreen(),
      debugShowCheckedModeBanner: false,
    );
  }
}

class Song extends StatelessWidget {
  const Song({ this.title, this.author, this.likes });

  final String title;
  final String author;
  final int likes;

  @override
  Widget build(BuildContext context) {
    TextTheme textTheme = Theme
      .of(context)
      .textTheme;
    return new Container(
      margin: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 5.0),
      padding: const EdgeInsets.symmetric(horizontal: 15.0, vertical: 10.0),
      decoration: new BoxDecoration(
        color: Colors.grey.shade200.withOpacity(0.3),
        borderRadius: new BorderRadius.circular(5.0),
      ),
      child: new IntrinsicHeight(
        child: new Row(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            new Container(
              margin: const EdgeInsets.only(top: 4.0, bottom: 4.0, right: 10.0),
              child: new CircleAvatar(
                backgroundImage: new NetworkImage(
                  'http://thecatapi.com/api/images/get?format=src'
                    '&size=small&type=jpg#${title.hashCode}'
                ),
                radius: 20.0,
              ),
            ),
            new Expanded(
              child: new Container(
                child: new Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: <Widget>[
                    new Text(title, style: textTheme.subhead),
                    new Text(author, style: textTheme.caption),
                  ],
                ),
              ),
            ),
            new Container(
              margin: new EdgeInsets.symmetric(horizontal: 5.0),
              child: new InkWell(
                child: new Icon(Icons.play_arrow, size: 40.0),
                onTap: () {
                  // TODO(implement)
                },
              ),
            ),
            new Container(
              margin: new EdgeInsets.symmetric(horizontal: 5.0),
              child: new InkWell(
                child: new Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    new Icon(Icons.favorite, size: 25.0),
                    new Text('${likes ?? ''}'),
                  ],
                ),
                onTap: () {
                  // TODO(implement)
                },
              ),
            ),
          ],
        ),
      ),
    );
  }
}

class Feed extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new ListView(
      children: [
        new Song(title: 'Trapadelic lobo', author: 'lillobobeats', likes: 4),
        new Song(title: 'Different', author: 'younglowkey', likes: 23),
        new Song(title: 'Future', author: 'younglowkey', likes: 2),
        new Song(title: 'ASAP', author: 'tha_producer808', likes: 13),
        new Song(title: 'You can use 
Stack
and can have its children as
Positioned
or
Align
.

Example #1 (Using
Positioned
in
Stack
)

Stack(
  children: <Widget>[
    Positioned(left: 0.0, child: Text("Top\nleft")),
    Positioned(bottom: 0.0, child: Text("Bottom\nleft")),
    Positioned(top: 0.0, right: 0.0, child: Text("Top\nright")),
    Positioned(bottom: 0.0, right: 0.0, child: Text("Bottom\nright")),
    Positioned(bottom: 0.0, right: 0.0, child: Text("Bottom\nright")),
    Positioned(left: width / 2, top: height / 2, child: Text("Center")),
    Positioned(top: height / 2, child: Text("Center\nleft")),
    Positioned(top: height / 2, right: 0.0, child: Text("Center\nright")),
    Positioned(left: width / 2, child: Text("Center\ntop")),
    Positioned(left: width / 2, bottom: 0.0, child: Text("Center\nbottom")),
  ],
)
Stack(
  children: <Widget>[
    Align(alignment: Alignment.center, child: Text("Center"),),
    Align(alignment: Alignment.topRight, child: Text("Top\nRight"),),
    Align(alignment: Alignment.centerRight, child: Text("Center\nRight"),),
    Align(alignment: Alignment.bottomRight, child: Text("Bottom\nRight"),),
    Align(alignment: Alignment.topLeft, child: Text("Top\nLeft"),),
    Align(alignment: Alignment.centerLeft, child: Text("Center\nLeft"),),
    Align(alignment: Alignment.bottomLeft, child: Text("Bottom\nLeft"),),
    Align(alignment: Alignment.topCenter, child: Text("Top\nCenter"),),
    Align(alignment: Alignment.bottomCenter, child: Text("Bottom\nCenter"),),
    Align(alignment: Alignment(0.0, 0.5), child: Text("Custom\nPostition", style: TextStyle(color: Colors.red, fontSize: 20.0, fontWeight: FontWeight.w800),),),
  ],
);
double _containerHeight = 120, _imageHeight = 80, _iconTop = 44, _iconLeft = 12, _marginLeft = 110;

@override
Widget build(BuildContext context) {
  return Scaffold(
    backgroundColor: Colors.white,
    body: Stack(
      children: <Widget>[
        Positioned(
          left: 0,
          right: 0,
          height: _containerHeight,
          child: Container(color: Colors.blue),
        ),
        Positioned(
          left: _iconLeft,
          top: _iconTop,
          child: Icon(Icons.settings, color: Colors.white),
        ),
        Positioned(
          right: _iconLeft,
          top: _iconTop,
          child: Icon(Icons.bubble_chart, color: Colors.white),
        ),
        Positioned(
          left: _iconLeft,
          top: _containerHeight - _imageHeight / 2,
          child: ClipOval(child: Image.asset("assets/images/profile.jpg", fit: BoxFit.cover, height: _imageHeight, width: _imageHeight)),
        ),
        Positioned(
          left: _marginLeft,
          top: _containerHeight - (_imageHeight / 2.5),
          child: Text("CopsOnRoad", style: TextStyle(color: Colors.white, fontWeight: FontWeight.w500, fontSize: 18)),
        ),
        Positioned.fill(
          left: _marginLeft,
          top: _containerHeight + (_imageHeight / 4),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Column(
                children: <Widget>[
                  Text("2", style: TextStyle(fontWeight: FontWeight.bold)),
                  Text("Gold", style: TextStyle(color: Colors.grey)),
                ],
              ),
              Column(
                children: <Widget>[
                  Text("22", style: TextStyle(fontWeight: FontWeight.bold)),
                  Text("Silver", style: TextStyle(color: Colors.grey)),
                ],
              ),
              Column(
                children: <Widget>[
                  Text("28", style: TextStyle(fontWeight: FontWeight.bold)),
                  Text("Bronze", style: TextStyle(color: Colors.grey)),
                ],
              ),
              Container(),
            ],
          ),
        ),
      ],
    ),
  );
}