- 浏览: 1055565 次
- 性别:
- 来自: 南昌
文章分类
- 全部博客 (276)
- 生活 (1)
- 代码之美 (22)
- Media (7)
- Android Widget (3)
- Android Intent (1)
- Android Activity (4)
- UI event handle--UI事件处理机制 (2)
- Java基础知识 (12)
- android Databases (5)
- Android 系统知识 (70)
- 平常遇到的问题与解决方法 (38)
- Android TextView/EditView (2)
- Thinking Java (1)
- android webkit (6)
- JSON (1)
- XML (4)
- HTTP (1)
- Google Weather API (1)
- android 2.3 NFC (10)
- android app (20)
- android framework (7)
- C++ (2)
- android System (5)
- Pthread (1)
- Wifi (8)
- Unix/Linux C (8)
- Android 4.0 (1)
- Mail (1)
- Smack 源码学习 (4)
- iOS (4)
- Android (1)
- git (1)
- Gallery3d (2)
- React-Natice (1)
最新评论
-
dd18349182956:
你是用的smack哪个版本?我用的smack4.1.3和sma ...
关于socket长连接的心跳包 -
xukaiyin:
全英文
getApplicationContext()与this,getBaseContext() -
裂风矢:
...
<category android:name="android.intent.category.DEFAULT" /> 惹的祸 -
xanthodont:
mark一下
XMPP——Smack -
Evilover3:
mark一下,学习了
XMPP——Smack
一直不明白android:layout_weight的作用,今天终于弄明白了。
转自:http://www.cnblogs.com/fly3q/archive/2010/03/24/1693977.html
layout_weight 用于给一个线性布局中的诸多视图的重要度赋值。
所有的视图都有一个layout_weight值,默认为零,意思是需要显示
多大的视图就占据多大的屏幕空 间。若赋一个高于零的值,则将父视
图中的可用空间分割,分割大小具体取决于每一个视图的layout_weight
值以及该值在当前屏幕布局的整体 layout_weight值和在其它视图屏幕布
局的layout_weight值中所占的比率而定。
举个例子:比如说我们在 水平方向上有一个文本标签和两个文本编辑元素。
该文本标签并无指定layout_weight值,所以它将占据需要提供的最少空间。
如果两个文本编辑元素每一个的layout_weight值都设置为1,则两者平分
在父视图布局剩余的宽度(因为我们声明这两者的重要度相等)。如果两个
文本编辑元素其中第一个的layout_weight值设置为1,而第二个的设置为2,
则剩余空间的三分之一分给第一个,三分之二分给第二个。
看例子:
附件为运行的效果:
更新于2012-10-29:
之前学得不够深,所以上面只是表面的解析,更深的可以读:http://www.chess-ix.com/2012/01/17/the-use-of-layout_weight-with-android-layouts/和http://www.cnblogs.com/angeldevil/archive/2012/html04/08/2437747
嗯,是啊!学艺不精!在不断地改正:这里有更好的解释:http://www.cnblogs.com/angeldevil/archive/2012/04/08/2437747.html[/url]和[url]http://www.chess-ix.com/2012/01/17/the-use-of-layout_weight-with-android-layouts/
大哥你的答案是对的!
按道理分析是会是1:2:3:4,但在实际情况中要考虑到其他的因素,比如我那实例代码中的TextView的宽度会受其text的字数影响的,因为有android:layout_width="wrap_content"这一句话。所以你可以看到我附件里面的那张效果图就明白了。
这位老兄说得对,一定要自己试试才知道。
转自:http://www.cnblogs.com/fly3q/archive/2010/03/24/1693977.html
layout_weight 用于给一个线性布局中的诸多视图的重要度赋值。
所有的视图都有一个layout_weight值,默认为零,意思是需要显示
多大的视图就占据多大的屏幕空 间。若赋一个高于零的值,则将父视
图中的可用空间分割,分割大小具体取决于每一个视图的layout_weight
值以及该值在当前屏幕布局的整体 layout_weight值和在其它视图屏幕布
局的layout_weight值中所占的比率而定。
举个例子:比如说我们在 水平方向上有一个文本标签和两个文本编辑元素。
该文本标签并无指定layout_weight值,所以它将占据需要提供的最少空间。
如果两个文本编辑元素每一个的layout_weight值都设置为1,则两者平分
在父视图布局剩余的宽度(因为我们声明这两者的重要度相等)。如果两个
文本编辑元素其中第一个的layout_weight值设置为1,而第二个的设置为2,
则剩余空间的三分之一分给第一个,三分之二分给第二个。
看例子:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1"> <TextView android:text="redwwwwwww" android:gravity="center_horizontal" android:background="#aa0000" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1"/> <TextView android:text="green" android:gravity="center_horizontal" android:background="#00aa00" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="2"/> <TextView android:text="blue" android:gravity="center_horizontal" android:background="#0000aa" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="3"/> <TextView android:text="yellow" android:gravity="center_horizontal" android:background="#aaaa00" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="4"/> </LinearLayout> </LinearLayout>
附件为运行的效果:
更新于2012-10-29:
之前学得不够深,所以上面只是表面的解析,更深的可以读:http://www.chess-ix.com/2012/01/17/the-use-of-layout_weight-with-android-layouts/和http://www.cnblogs.com/angeldevil/archive/2012/html04/08/2437747
评论
9 楼
追求幸福
2012-10-29
a455642158 写道
整体竖直方向是这个分配率 内部进去就相反了……表面现象解释。
嗯,是啊!学艺不精!在不断地改正:这里有更好的解释:http://www.cnblogs.com/angeldevil/archive/2012/04/08/2437747.html[/url]和[url]http://www.chess-ix.com/2012/01/17/the-use-of-layout_weight-with-android-layouts/
8 楼
a455642158
2012-08-29
整体竖直方向是这个分配率 内部进去就相反了……表面现象解释。
7 楼
z576250965
2012-03-22
既然和android:layout_width="wrap_content"有关,那android:weight不就可有可无了吗?
6 楼
追求幸福
2012-01-04
sunjiesh 写道
为什么我得到的是相反的答案呢?我已经确保使TEXT中的内容相同,但是发现效果是反而是android:layout_weight数值大的反而占据的空间大呢?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="3" android:background="#aa0000" android:gravity="center_horizontal" android:text="XXXX" /> <TextView android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1" android:background="#00aa00" android:gravity="center_horizontal" android:text="XXXX" /> <TextView android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1" android:background="#0000aa" android:gravity="center_horizontal" android:text="XXXX" /> <TextView android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="3" android:background="#aaaa00" android:gravity="center_horizontal" android:text="XXXX" /> </LinearLayout>
大哥你的答案是对的!
5 楼
sunjiesh
2012-01-02
为什么我得到的是相反的答案呢?我已经确保使TEXT中的内容相同,但是发现效果是反而是android:layout_weight数值大的反而占据的空间大呢?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="3" android:background="#aa0000" android:gravity="center_horizontal" android:text="XXXX" /> <TextView android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1" android:background="#00aa00" android:gravity="center_horizontal" android:text="XXXX" /> <TextView android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1" android:background="#0000aa" android:gravity="center_horizontal" android:text="XXXX" /> <TextView android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="3" android:background="#aaaa00" android:gravity="center_horizontal" android:text="XXXX" /> </LinearLayout>
4 楼
追求幸福
2011-07-04
liuwanwei 写道
图中的水平宽度比率是4:3:2:1吗?
按道理分析是会是1:2:3:4,但在实际情况中要考虑到其他的因素,比如我那实例代码中的TextView的宽度会受其text的字数影响的,因为有android:layout_width="wrap_content"这一句话。所以你可以看到我附件里面的那张效果图就明白了。
3 楼
追求幸福
2011-07-04
liang86liang 写道
跑跑试试,实践出真知么!!哈哈
这位老兄说得对,一定要自己试试才知道。
2 楼
liang86liang
2011-07-01
跑跑试试,实践出真知么!!哈哈
1 楼
liuwanwei
2011-06-30
图中的水平宽度比率是4:3:2:1吗?
发表评论
-
打印调用堆栈
2019-11-15 15:48 443平常我们遇到不清楚代码逻辑的,可以通过打印调用堆栈来理清楚,如 ... -
你知道Log.isLoggable
2018-11-23 14:15 841我们可以通过Log.isLoggable来动态开关log的输出 ... -
android:allowUndo
2018-04-25 16:51 752Android 在Android 23增加了UndoManag ... -
mipmap-xxx
2015-12-10 11:35 1061最近在看AOSP,发现mipmaps, 百度 了一下,发现有各 ... -
《Android.Programming.Pushing.the.Limits].Erik.Hellman》记录1
2015-10-29 10:56 550最近在看《Android.Programming.Pushin ... -
System.currentTimeMillis() uptimeMillis elapsedRealtime 区别
2015-10-28 20:02 1272转自http://blog.csdn.net/wutianyi ... -
GPS的开关设置
2015-09-29 18:36 1981//modify by hyxu 2015-9-30 to s ... -
DialogFragment
2015-09-25 13:56 1007public class YesNoDialog extend ... -
ANDROID L——RecyclerView,CardView导入和使用
2015-07-23 09:51 915转自http://blog.csdn.net/a3969019 ... -
IntentService 和ResultReceiver
2015-07-22 20:00 786转自[url] http://javatechig.com/a ... -
Android media媒体库分析之:分类别统计媒体文件大小
2015-07-21 20:07 526转自http://www.linuxidc.com/Linux ... -
java.lang.IllegalArgumentException: Service Intent must be explicit
2015-07-21 20:03 1278转自:http://www.2cto.com/kf/20150 ... -
Context 和Application Context
2015-02-11 15:14 863http://possiblemobile.com/2013/ ... -
ContentProviderOperation.Builder 中withValue和withValueBackReference的区别
2015-02-10 14:01 2177关于ContentProviderOperation.Buil ... -
AndroidManifest.xml的Service元素 android:process设置
2013-05-30 17:02 11460转自:http://galin.blog.sohu ... -
android中打包含有Activity以及资源文件的jar包在工程中调用
2013-05-28 15:00 1293转自:http://www.cnblogs.com/vaiya ... -
Android杂谈--内存泄露(1)--contentView缓存使用与ListView优化
2012-11-01 09:29 2799转自:http://www.cnblogs.com/louli ... -
Handler+ExecutorService(线程池)+MessageQueue模式+缓存模式
2012-10-31 14:32 1854转自:http://www.eoeandroid.com/th ... -
Animation
2012-10-30 13:41 1108转自:http://hi.baidu.com/wendaoer ... -
Android onTouchEvent和onInterceptTouchEvent
2012-10-24 15:05 1262ViewGroup里的onInterceptTouchEven ...
相关推荐
用Eclipse加载项目工程 <LinearLayout xmlns:android=... android:layout_weight="0.66" android:background="@drawable/blue_bg" android:orientation="vertical" > android:layout
-<LinearLayout android:background="@drawable/aaa" android:weightSum="1" android:layout_height="match_parent" android:layout_width="match_parent" android:orientation="vertical" xmlns:android=...
-<LinearLayout android:background="@drawable/aaa" android:weightSum="1" android:layout_height="match_parent" android:layout_width="match_parent" android:orientation="vertical" xmlns:android=...
android:layout_weight="1" android:layout_height="wrap_content" android:text="行1列2" /> <TextView android:layout_width="wrap_content" android:layout_weight="1" android:layout_height="wrap_content...
我用的是HorizontalScrollView来实现水平条的滚动,按钮的背景宽度和图片的一致,以免被拉伸,main.xml的配置如下: <LinearLayout xmlns:android=... android:layout_weight="1" >
android:layout_weight="1" android:id="@+id/vp" android:layout_width="match_parent" android:layout_height="0dp"></android.support.v4.view.ViewPager> <LinearLayout android:paddingTop="10dp" ...
android:layout_weight="1" android:src="@drawable/pbg" android:scaleType="centerCrop"/> android:id="@+id/m3" android:layout_margin= "2dp" android:layout_width="60dp" android:layout_height=...
android:layout_weight="10" android:text="http://www.imust.cn/info/1062/5273.htm" /> android:id="@+id/bt_go" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_...
如果LinearLayout是最外面的一层,它是不会弹出layout_weight属性的, 换句话说最外层不能用layout_weight xml布局如下 <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:...
<Button android:id="@+id/example_row_b_action_2" android:layout_width="0dp" android:layout_height="60dp" android:layout_gravity="center" android:layout_marginLeft="10dp" android:layout_weight="1" ...
package xatu.cn.androidtest_one; import android.content.ContentResolver; import android.content.Intent;... android:layout_weight="1" /> </LinearLayout> </android.support.constraint.ConstraintLayout>
layout_weight的作用是设置子空间在LinearLayout的重要度(控件的大小比重)。layout_weight的值越低,则控件越重要,下面为大家介绍下具体的使用方法
android:layout_weight="1"> <android.support.v4.view.ViewPager android:id="@ id/viewpager_default" android:layout_width="match_parent" android:layout_height="match_parent"/> ...
android:layout_weight="1"> </android.support.v4.view.ViewPager> android:layout_width="match_parent" android:layout_height="0.5dp" android:background="#737373" /> android:layout_width=...
android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent"/> android:onClick="scrollTo3" android:background="@android:color/holo_green_light" android:...
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”match_parent” android:layout_height=”match_parent” android:orientation=”horizontal”> <...
android:layout_weight="1" android:layout_height="wrap_content" android:layout_marginLeft="15dp" android:layout_marginTop="5dp" android:layout_marginBottom="5dp" android:layout_marginRight="10dp...
android:id="@+id/dir_str" android:gravity="center" android:layout_weight="1" /> --> android:id="@+id/btn_back" android:layout_width="40dip" android:layout_height="40dip" android:text="BACK" ...
为了创建比例大小的子View,可以将LinearLayout的宽度和...对于LinearLayout的几个子View,将它们的宽度都定义为0,android:layout_width=”0dip”,然后使用layout_weight 为每个View指定宽度比例,本例为每个TextVie
android:layout_weight—– 给控件分配剩余空间 先给大家展示一下导图: 知识点详解(演示效果方便组件没有设置id) (1)gravity和Layout_gravity android:gravity 属性是对该view中内容的限定.比如一个...