嗨,今天我来分享一下Android中的布局,布局我今天为大家分享其中一个简单的布局:流式布局 1.所谓的流式布局,就是像流水一样直接自动从左到右,自动排序
然后通过控制其属性控制控件的位置,从而达到控制其位置,大家可以试着做一下下面这个题,对于刚入门Android的童鞋来说好玩到爆(@ ̄ー ̄@)
对,不用其他布局,只用流式布局来写这个,需要动一下你的脑筋,不要小看哦,也希望有童鞋有跟我的解决方案不同的话,可以在下面回复,让本人瞄俩眼也是可以的,O(∩_∩)O哈哈~
∨
∨
∨
∨下面加上我的写法
∨
∨
∨
∨
∨
首先,将orientation属性设置为horizontal,就是将他的大Linear设置为水平
然后在定义三个小的Linear
并且将三个的Width全设置为Wrap Content ,,Height全设置为、Matc Parent
然后在每个小Linear里面先创建一个Button
然后设置其每个Linear的Weight为0.3
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.3">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我是左上"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.3">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我是中间"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.3">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我是右上"/>
</LinearLayout>
附加效果图
然后在设置其在所在的地方
左上的设置
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.3">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我是左上"
android:layout_gravity="left"/>
 </LinearLayout>
这样看上去没效果
再然后设置中间的
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.3"
android:gravity="center">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我是中间"/>
</LinearLayout>
附加效果图
效果显著
移到最中间了<( ̄ˇ ̄)/
然后处理右边的,移到右上角
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.3"
android:gravity="right">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我是右上"/>
</LinearLayout>
然后再附加效果图
再然后处理下面两个
在右边那个小Linear属性orientation设置为垂直(Vertical),gravity=”right”
在右边那个小Linear里面嵌套一个小小Linear,并且写个Button
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.3"
android:gravity="right"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我是右上"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.3"
android:gravity="right">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我是右下"/>
</LinearLayout>
</LinearLayout>
效果图。。。。ヾ(´∀`o)+
再设置小小Linear的button 中的layout_gravity设置为bottom
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.3"
android:gravity="right"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我是右上"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.3"
android:gravity="right">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我是右下"
android:layout_gravity="bottom"/>
</LinearLayout>
</LinearLayout>
=.=效果图
完美哈哈哈,然后左边的跟上面进行差不多的处理,然后写完=.=
附加最后处理完的图 今天就分享这么多,哇咔咔