Android线性布局LinearLayout,及盒模型,weight权值,ScrollView和HorizontalScrollView【内容溢出(内容太多,高度/宽度大于能显示的最大高度/宽度)】
来源:互联网 发布:陈冠希艳照门事件知乎 编辑:程序博客网 时间:2024/06/05 10:25
工作内容:
1.ScrollView和HorizontalScrollView的讲解:【内容溢出——在最外层使用ScrollView/HorzontalScrollView来添加一个滚动条,滚动显示】ScrollView中的单一控件或布局控件可以使用layout_gravity来设置控件在ScrollView中的布局位置(演示效果:可以上下左右滑动——宽度大于可现实最大宽度HorizontalScrollView)
注意点:横向和竖向都应该和LinearLayout的orientation联合使用:
ScrollView——orientation="vertical"竖向滚动
HorzontalScrollView——orientation="horzontalScrollView" 横向滚动
例子;
<!--横向滚动条--><HorizontalScrollView<span style="white-space:pre"></span><!--与子布局(LinearLayout的orientation)同时使用--> android:layout_width="match_parent" android:layout_height="wrap_content" android:overScrollMode="always" > <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:layout_gravity="center_vertical" android:orientation="horizontal" android:background="@color/colorAccent"></LinearLayout></HorizontalScrollView>
2.LinearLayout布局的嵌套使用
3.Margin:外边距的使用【不会让控件的宽高发生变化】会占用父布局宽高【点击控件宽高范围内有效,margin区无效】
4.Padding:内边距的使用【不会让控件的宽高发生变化】先占用内容区之外的区域,之后再占用内容区域
5.Gravity:left|center设置内容在容器的左中
6.Weight/weightSum:weight只权重——【用于LinearLayout】当前view占父布局的weightSum的宽度,长度=weight/weightSum
注意:组件需用/>扩回,<LinearLayout ...></LinearLayout>
盒模型:
实例:
<!--计算器的的布局-->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="7"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|left"
android:layout_weight="1"
android:id="@+id/text_old"
android:paddingLeft="5dp"
android:textSize="20sp"
android:textColor="#000"
android:text="0" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center_vertical|left"
android:layout_weight="1"
android:id="@+id/text_new"
android:paddingLeft="5dp"
android:textSize="20sp"
android:textColor="#000"
android:maxLines="1"
android:text="0" />
<TextView
android:layout_width="40dp"
android:layout_height="wrap_content"
android:gravity="center_vertical|right"
android:id="@+id/text_symbol"
android:paddingLeft="5dp"
android:textSize="20sp"
android:textColor="#000"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" >
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="@+id/btn_7"
android:text="7"
/>
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="@+id/btn_8"
android:text="8"
/>
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="@+id/btn_9"
android:text="9"
/>
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="@+id/btn_add"
android:text="+"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" >
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="@+id/btn_4"
android:text="4"
/>
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="@+id/btn_5"
android:text="5"
/>
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="@+id/btn_6"
android:text="6"
/>
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="@+id/btn_cut"
android:text="-"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" >
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="@+id/btn_1"
android:text="1"
/>
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="@+id/btn_2"
android:text="2"
/>
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="@+id/btn_3"
android:text="3"
/>
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="@+id/btn_mul"
android:text="*"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" >
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="@+id/btn_0"
android:text="0"
/>
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="@+id/btn_spot"
android:text="."
/>
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="@+id/btn_get"
android:text="="
/>
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="@+id/btn_except"
android:text="/"
/>
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/btn_clear"
android:text="清空"
/>
</LinearLayout>
- Android线性布局LinearLayout,及盒模型,weight权值,ScrollView和HorizontalScrollView【内容溢出(内容太多,高度/宽度大于能显示的最大高度/宽度)】
- Android 获取WebView的内容宽度高度
- Android HorizontalScrollView 内容宽度
- 如何获取LinearLayout的宽度和高度?
- 获取LinearLayout的宽度和高度
- android 如何获取LinearLayout的宽度和高度?
- 获取文本内容高度和宽度
- 根据文本内容快速自适应控件的宽度和高度
- 获取手机屏幕、屏幕内容的高度和宽度
- 动态设置HorizontalScrollView中imageview的宽度和高度
- winform窗口的最大宽度和高度
- 二叉树的最大宽度和高度
- IE6的最大最小高度和宽度
- 重新调整布局的宽度和高度
- 布局控件的宽度和高度设定
- CSS的最大高度,最小高度及宽度问题
- 盒子模型的高度和宽度
- IOS聊天泡泡,根据内容计算宽度和高度(动态计算高度和宽度)
- Android之ViewPagerindicator
- Android:学习AIDL,这一篇文章就够了(下)
- 解决nginx负载均衡的session共享问题
- 数据库测试
- win7 64位MySQL安装
- Android线性布局LinearLayout,及盒模型,weight权值,ScrollView和HorizontalScrollView【内容溢出(内容太多,高度/宽度大于能显示的最大高度/宽度)】
- C语言中加法在内存中的运行
- 猫捉老鼠
- Wifi小车之 - 综合调试篇
- Appium自动化测试工具介绍(一)
- Codeforces Round #202 (Div. 1) A. Mafia二分查找,玩游戏
- Light OJ:1137 Expanding Rods(二分+几何数学)
- Hbase结合mapreduce需要导入的hbase lib及部分问题持续更
- android日常整理