关于Linearlayout里weight与子布局的wrap content
来源:互联网 发布:gopro windows 编辑:程序博客网 时间:2024/05/18 00:41
布局文件为下
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context="baseapp.dawnpro.com.textdemo.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical">
<LinearLayout
android:clipChildren="false"
android:weightSum="6"
android:id="@+id/ll"
android:layout_width="match_parent"
android:layout_height="44dp"
android:background="#6785EA"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/id1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:text="Hello World!"
android:textColor="#ffffff"/>
<View
android:id="@+id/id2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#f73912"/>
<TextView
android:id="@+id/id3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#f73947"
android:text="超级无敌无敌超级无敌无敌超级无敌无敌超级无敌无敌超级无敌无敌"
android:textColor="#ffffff"/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
需求是一个标题在左,一个内容在右,实际情况使用相对布局很好实现,我这里是改的别人的自定义控件,他的根布局是linearlayout.
使用一个weight为1的view将内容textview顶到linearlayout右边;
这里主要的问题是textview一行能显示的下的时候,textview不会超出屏幕,如果textview在屏幕内显示不下或者需要换行,textview的宽度就会超出屏幕,或者说超出linearlayout.
如果删除weight为1的view,textview就不会超过屏幕,可以正常换行将所有内容显示在屏幕内
查了一些资料,对android的weight实现过程也了解一下(经常在用 http://blog.csdn.net/chy800/article/details/46397927 ),不过这里出现这个超出父控件范围的问题还是无法理解
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context="baseapp.dawnpro.com.textdemo.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical">
<LinearLayout
android:clipChildren="false"
android:weightSum="6"
android:id="@+id/ll"
android:layout_width="match_parent"
android:layout_height="44dp"
android:background="#6785EA"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/id1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:text="Hello World!"
android:textColor="#ffffff"/>
<View
android:id="@+id/id2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#f73912"/>
<TextView
android:id="@+id/id3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#f73947"
android:text="超级无敌无敌超级无敌无敌超级无敌无敌超级无敌无敌超级无敌无敌"
android:textColor="#ffffff"/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
需求是一个标题在左,一个内容在右,实际情况使用相对布局很好实现,我这里是改的别人的自定义控件,他的根布局是linearlayout.
使用一个weight为1的view将内容textview顶到linearlayout右边;
这里主要的问题是textview一行能显示的下的时候,textview不会超出屏幕,如果textview在屏幕内显示不下或者需要换行,textview的宽度就会超出屏幕,或者说超出linearlayout.
如果删除weight为1的view,textview就不会超过屏幕,可以正常换行将所有内容显示在屏幕内
查了一些资料,对android的weight实现过程也了解一下(经常在用 http://blog.csdn.net/chy800/article/details/46397927 ),不过这里出现这个超出父控件范围的问题还是无法理解
阅读全文
1 0
- 关于Linearlayout里weight与子布局的wrap content
- 相对布局LinearLayout权重weight的用法
- LinearLayout布局中的weight的理解
- LinearLayout(线性布局)中weight的难点
- Android 布局之LinearLayout 子控件weight权重的作用详析
- Android 布局之LinearLayout 子控件weight权重的作用详析
- Android 布局之LinearLayout 子控件weight权重的作用详析
- Android 布局之LinearLayout 子控件weight权重的作用详析
- 关于LinearLayout中的weight的属性
- 在LinearLayout里动态添加子布局
- Android LinearLayout布局嵌套及权重weight的使用
- Android中LinearLayout布局的Weight属性详解
- LinearLayout 子控件weight权重的作用详析
- LinearLayout的weight
- LinearLayout关于weight使用问题
- 安卓布局里“layout_height”设为wrap与match的差别
- LinearLayout中weight的学习
- android LinearLayout的weight问题
- jfinal下部署maven项目遇到的问题及解决方法
- 树中第一个公共祖先结点----解法
- 单元测试Qunit
- WIN7系统下U盘安装Ubuntu双系统
- Android用VideoView实现MP4作为页面背景(仿QQ登录页面效果)
- 关于Linearlayout里weight与子布局的wrap content
- php模拟长连接
- VS2010的编码经验
- tomcat大量time wait问题
- Spring Data JPA入门
- #bzoj1846
- 破解防拷贝脚本
- C 预处理器和C库
- MyBatis的知识点