android layout 按比例布局

摘要:
为了创建比例大小的子View,可以将LinearLayout的宽度和高度设为fill_parent,而将子View的宽度或是高度设为0,然后为子View设置不同权重,这样子View的大小就会权值成比例。对于LinearLayout的几个子View,将它们的宽度都定义为0,android:layout_width=”0dip”,然后使用layout_weight为每个View指定宽度比例,本例为每个TextView都使用了相同的权值,因此四个TextView将会有相同的宽度。这样对于那些显示文字比较长的TextView的高度就变为多行。

为了创建比例大小的子View,可以将LinearLayout的宽度和高度设为fill_parent, 而将子View的宽度或是高度设为0,然后为子View设置不同权重(weight) ,这样子View的大小就会权值成比例。

本例使用横向LinearLayout,LinearLayout的android:layout_width=”match_parent”,表示将使用整个屏幕宽度。

对于LinearLayout的几个子View,将它们的宽度都定义为0,android:layout_width=”0dip”,然后使用layout_weight 为每个View指定宽度比例,本例为每个TextView都使用了相同的权值,因此四个TextView将会有相同的宽度。这样对于那些显示文字比较长的TextView的高度就变为多行。

<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”android:orientation=”horizontal”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”>

<TextView
android:background=”@drawable/red”
android:layout_width=”0dip”
android:layout_height=”match_parent”
android:layout_weight=”1″
android:text=”@string/linear_layout_7_small”/>

<TextView
android:background=”@drawable/green”
android:layout_width=”0dip”
android:layout_height=”match_parent”
android:layout_weight=”1″
android:text=”@string/linear_layout_7_big”/>

<TextView
android:background=”@drawable/blue”
android:layout_width=”0dip”
android:layout_height=”match_parent”
android:layout_weight=”1″
android:text=”@string/linear_layout_7_small” />

<TextView
android:background=”@drawable/yellow”
android:layout_width=”0dip”
android:layout_height=”wrap_content”
android:layout_weight=”1″
android:text=”@string/linear_layout_7_wrap”/>

</LinearLayout>

免责声明:文章转载自《android layout 按比例布局》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇C#设计模式-享元模式react 简单搭建下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Android 中 Environment.getExternalStorageDirectory()无效

我们在处理缓存的时候,并不是每次都会在应用私有存储空间那里保存,很多时候是需要用到ExternalStorage。我们平时一般都是用Environment.getExternalStorageDirectory(),这在6.0以前一直是好的,(即使不对,那你的问题应该是没注意加权限,或者是格式不对之类又或者sdcard被移走了等等)。但是到了6.0以后,就...

黑马android

day55 1、AndroidManifest.xml 中对某个Activity设置全屏:android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" 2、(image)View.setBackgroundResource() 这种情况会全屏设置背景 3、drawable文件夹下的sele...

android:ViewPager实现Tabs滑动切换效果

进入ViewPager官方文档 public class ViewPager extends ViewGroup java.lang.Object    ↳ android.view.View      ↳ android.view.ViewGroup        ↳ android.support.v4.view.ViewPager...

uniapp打包h5页面ios唤起软键盘踩坑

问题:页面有很多input框,上面的input输入框,当虚拟键盘出来时没问题,但是下面的input输入框,就会出现问题,input输入框会跑到键盘后面。 网上一阵百度,找到原因:安卓手机中唤起软键盘时页面会压缩webview的高度,窗口会执行resize事件,但ios并不会。网上各种百度,尝试,都失败了,在快放弃时,找到一个可行的。直接贴代码: 1...

vue移动端预览pdf

vue-pdf移动端缺点: 1、安卓预览红头文件会出现缺字少字的问题,ios正常 2、预览过大文件,分页形式的好用,不分页的文件过大可能打不开 3、分页形式放大缩小只能通过按钮改变css放大,不分页无法放大 解决vue-pdf移动端问题使用pdfh5预览pfd: 1.安装 npm install pdfh5 2.使用 <template>...

安卓手机无法使用adb导出文件

adb pull 无法使用 问题:在使用adb pull 文件到本地时无法导出 提升adb root 权限 - 失败,只有进入adb shell 然后su 提升,还是无法导出 解决方法 给需要导出的文件夹:读写执行的权限也是777,所有的勾上 注意使用命令行形式提升权限可能无法生效,也就是无法导出 软件为Android Killer 自带的An...