android布局中线型比例,Android五布局——线性布局LinearLayout

1、线性布局:

在res->layout->activity_main.xml文件中,如果有LinearLayout控件,其中可添加控件,则这些控件的布局就是线性布局。

2、LinearLayout:

LinnearLayout是线性布局控件,它包含的子控件将以横向或者竖向的方式排列。

3、LinearLayout常用属性:

LinearLayout本身常用到的两个属性:

android:orientation="vertical"    该属性决定它子类控件的排布方式(vertical:垂直;horizontal:水平)

android:gravity="center"    该属性决定它子类的xy的位置

常用到的几个属性值:

center_vertical    垂直居中

center_horizontal    水平居中

center    水平垂直都居中

right    子类控件位于当前布局的右边

left    子类控件位于当前布局的左边

bottom    子类控件位于当前布局的下面

4、LinearLayout子类控件常用到的属性

android:layout_gravity="bottom"     本身在当前父容器的位置

android:layout_weight="1"     本身占当前父容器的比例

5、LinearLayout的使用

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingBottom="@dimen/activity_vertical_margin"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

tools:context=".MainActivity"

android:orientation="vertical"

android:gravity="center">

android:id="@+id/textView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/fuck" />

android:id="@+id/textView2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/fuck" />

6f78a3cacb9f60b26927c9f8ecc1cef8.png

6、各属性可以多级联用

例如希望控件既靠下又能在水平方向居中,则可以写为:

android:gravity="bottom/center_horizontal"

7、子类控件属性 android:layout_weight="1"的用法注意

如果android:layout_height="wrap_content"则与比例相同,例如两个按钮,第一个按钮占两份,第二个按钮占一份,则按钮的布局与比例相同。

如果android:layout_height="match_content"则与比例相反,例如两个按钮,第一个按钮占一份,第二个按钮占两份,则按钮的布局与比例相反。

8、布局方式可以多级联用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值