用权重来实现屏幕自适应
来源:互联网 发布:怎么ping端口号 编辑:程序博客网 时间:2024/05/01 21:48
用权重来实现屏幕自适应
一直以来没能有时间去整理屏幕自适应的问题,今天特地整理了一部分。
-安卓手机的屏幕大小种类很多,安卓的屏幕自适应就显得非常重要了
首先直接上代码
代码块
新建一个项目Test_screen,在其布局文件activity_main.xml中的代码如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:orientation="horizontal" android:background="#ff00ff"> <View android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="#00ef00" /> <View android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="#ffef00" /> <View android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="#00efff" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:orientation="vertical" android:background="#0000ff"> <View android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="#afa10f" /> <View android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="#ffdc0e" /> <View android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="#94ba0e" /> </LinearLayout></LinearLayout>
代码解析:首先在手机上放置两个控件,设置权重都是1,特别说明一下,android:layout_weight设置权重最好用 android:layout_width="0dp"或者 android:layout_height="0dp"来匹配,当然 android:layout_height设置为match_parent也是可以的,但是匹配起来的方法就会有很多种方法了,建议把控件的高或者宽设置为0。通过设置宽或高是0dp就可以使控件成正比例显示。程序运行结果如下图:![程序运行结果如下图](http://img.blog.csdn.net/20151026132905158)----------,
对安卓不是很熟悉,如有什么错误或者有更好的建议欢迎评论予以指正!谢谢!
0 0
- 用权重来实现屏幕自适应
- Android----实现屏幕自适应
- 用CSS来实现网页自适应设计
- 实现一屏幕自适应登陆
- webView 自适应屏幕 的实现
- css实现自适应屏幕高度
- swift实现自适应屏幕源码
- css实现自适应屏幕高度
- Smobiler中通过Scrollable和AutoHeight属性来实现手机上屏幕自适应(开发日志十三)
- Android自适应屏幕的实现方法
- android如何实现屏幕的自适应
- js实现跨设备自适应屏幕
- @media screen实现屏幕自适应内容详解
- 自适应屏幕大小的网页是怎么做出来的
- 屏幕自适应
- 屏幕自适应
- 屏幕自适应
- 屏幕自适应
- struts2的流程跳转
- 拓扑排序+优先级队列
- Set Programming Guide
- Android实现带动画的下拉刷新RecyclerView
- Java深度拷贝一个对象
- 用权重来实现屏幕自适应
- 安卓安全工具集整理
- jquery reset form/submit form
- TERADATA中函数的使用
- 抢购 多线程
- Scroller、scrollTo、ScrollBy学习笔记
- 搭建高可用mongodb集群(四)—— 分片
- cookie详解
- hi,all