Android 相对布局 各控件指之间的间距怎么设置
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android 相对布局 各控件指之间的间距怎么设置相关的知识,希望对你有一定的参考价值。
参考技术A android:layout_marginTop="25dip" //顶部距离android:layout_marginLeft="15dip" //距离左边距本回答被提问者和网友采纳 参考技术B 设置Marggin属性指定外边距 android:layout_margin="5dip"
Masonry的一些等间距布局
- 控件之间的间距相等,但是控件的宽度是不定的。
下列的代码:定义间距为10,yellowview的宽度是由redView的宽度计算出来的。
UIView *redView = [[UIView alloc]init]; redView.backgroundColor = [UIColor redColor]; [self.view addSubview:redView]; [redView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(ws.view); make.top.mas_equalTo(ws.view); make.right.mas_equalTo(ws.view); }]; NSInteger padding = 10; UIView *yellowView1 = [[UIView alloc] init]; yellowView1.backgroundColor = [UIColor yellowColor]; [redView addSubview:yellowView1]; UIView *yellowView2 = [[UIView alloc] init]; yellowView2.backgroundColor = [UIColor yellowColor]; [redView addSubview:yellowView2]; UIView *yellowView3 = [[UIView alloc] init]; yellowView3.backgroundColor = [UIColor yellowColor]; [redView addSubview:yellowView3]; [@[yellowView1,yellowView2,yellowView3] mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:padding leadSpacing:padding tailSpacing:padding]; [@[yellowView1,yellowView2,yellowView3] mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(redView).offset(padding); make.height.mas_equalTo(yellowView1.mas_width); make.bottom.mas_equalTo(redView).offset(-padding); }];
- 控件的宽度是一定的,但是控件之间的间距是不定的。
下列的代码:定义控件的宽度为22,控件之间的间距是由redView的宽度计算出来的。
UIView *redView = [[UIView alloc]init]; redView.backgroundColor = [UIColor redColor]; [self.view addSubview:redView]; [redView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(ws.view); make.top.mas_equalTo(ws.view); make.right.mas_equalTo(ws.view); }]; UIView *yellowView1 = [[UIView alloc] init]; yellowView1.backgroundColor = [UIColor yellowColor]; [redView addSubview:yellowView1]; UIView *yellowView2 = [[UIView alloc] init]; yellowView2.backgroundColor = [UIColor yellowColor]; [redView addSubview:yellowView2]; UIView *yellowView3 = [[UIView alloc] init]; yellowView3.backgroundColor = [UIColor yellowColor]; [redView addSubview:yellowView3]; //控件的宽度 CGFloat viewW = 22; CGFloat padding = (SCREENWIDTH - 3*viewW) * 1.0 / 4; [@[yellowView1,yellowView2,yellowView3] mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedItemLength:viewW leadSpacing:padding tailSpacing:padding]; [@[yellowView1,yellowView2,yellowView3] mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(redView).offset(padding); make.size.mas_equalTo(viewW); make.bottom.mas_equalTo(redView).offset(-padding); }];
以上是关于Android 相对布局 各控件指之间的间距怎么设置的主要内容,如果未能解决你的问题,请参考以下文章
android常用的布局管理器都有哪些,简述各布局管理器的布局特点
css 田字布局,子元素之间,子元素和父元素之间间距10,自适应
Android-ConstraintLayout(约束布局)-Centering/Circular and with Bias了解一下