学习android的布局
16lz
2021-01-24
在我自己的手机上(G12,系统版本2.3.3)。以下布局,无法在手机上看到THR:
- <LinearLayout
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:layout_weight="1"
- android:background="#AABBCC">
- <TextViewandroid:text="ONE"
- android:background="#aa0000"
- android:layout_height="fill_parent"
- android:layout_width="fill_parent"
- android:gravity="center"
- android:layout_weight="1"/>
- <TextViewandroid:text="TWO"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:background="#00aa00"
- android:gravity="center"
- android:layout_weight="2"/>
- <TextViewandroid:text="THR"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:layout_weight="3"
- android:background="#0000aa"
- android:gravity="center"/>
- </LinearLayout>
讲解layout_weight配合LinearLayout使用的文章:
layout_weight体验(实现按比例显示):
http://www.cnblogs.com/zhmore/archive/2011/11/04/2236514.html
还有一篇,android布局参数详解:
http://blog.csdn.net/trampou/article/details/5752533
综合实例:
LinearLayout嵌套ScrollView,ScrollView中再嵌套LinearLayout,LinearLayout中再嵌套很多按钮等控件:
- <LinearLayout
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <ScrollView
- android:layout_width="fill_parent"
- android:layout_height="0dp"
- android:scrollbars="vertical"
- android:fadeScrollbars="false"
- android:layout_weight="2">
- <LinearLayoutandroid:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- >
- <Button
- android:id="@+id/StartMusic"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="开始"/>
- <Button
- android:id="@+id/FrontButton"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="前一首"/>
- <Button
- android:id="@+id/LastMusic"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="最后一首"/>
- <SeekBar
- android:id="@+id/audioVolume"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- />
- <SeekBar
- android:id="@+id/seekbar01"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- />
- </LinearLayout>
- </ScrollView>
- ...(其他布局或ScrollView)
- </LinearLayout>
更多相关文章
- android BaseAdapter优化
- Android(安卓)内存泄漏 - 不要用static修饰控件
- Android常用控件-DatePicker以及对话框的两种使用方法
- 在Android线程中设置控件的值会报错
- Android(安卓)RecycerView 中根据图片大小自适应控件大小的实现
- Android中View绘制优化二一---- 使用标签复用布局文件
- Android(安卓)实现仿支付宝的密码均分输入框
- 用RelativeLayout布局可以在imageview中写上文字
- Android(安卓)ViewPager 几种开发案例的使用