布局文件为下
<?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 ),不过这里出现这个超出父控件范围的问题还是无法理解