关于Linearlayout里weight与子布局的wrap content

布局文件为下
<?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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值