下边这个是布局文件
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical"
android:fadingEdge="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/outerlayout"
android:orientation="vertical"
android:background="#374045"
android:paddingLeft="8dp"
android:paddingRight="8dp">
</LinearLayout>
</ScrollView>下边这个是要添加到上边LinearLayout中的布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="90dp"
android:orientation="vertical">
<TextView android:id="@+id/singer_new_ttl"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:textSize="15sp"
android:textColor="#e1e1e1"
android:singleLine="false"/>
<TextView
android:id="@+id/tx_fromanddate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#808080"
android:textSize="13sp"/>
</LinearLayout>问题是这样的,如果把下边的布局直接放到上边的LinearLayout中显示正常,比如只有一行文字也会显示90dp的高度,但是如果通过inflate下边的布局然后再addView到上边LinearLayout中就不会是固定的90dp,比如只有一行字那就只有一行的高度,这是为什么呢,一直没搞明白原因inflateaddView
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical"
android:fadingEdge="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/outerlayout"
android:orientation="vertical"
android:background="#374045"
android:paddingLeft="8dp"
android:paddingRight="8dp">
</LinearLayout>
</ScrollView>下边这个是要添加到上边LinearLayout中的布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="90dp"
android:orientation="vertical">
<TextView android:id="@+id/singer_new_ttl"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:textSize="15sp"
android:textColor="#e1e1e1"
android:singleLine="false"/>
<TextView
android:id="@+id/tx_fromanddate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#808080"
android:textSize="13sp"/>
</LinearLayout>问题是这样的,如果把下边的布局直接放到上边的LinearLayout中显示正常,比如只有一行文字也会显示90dp的高度,但是如果通过inflate下边的布局然后再addView到上边LinearLayout中就不会是固定的90dp,比如只有一行字那就只有一行的高度,这是为什么呢,一直没搞明白原因inflateaddView
解决方案 »
- (新手自学)遇到了个关于android中session的问题
- 请教:SurfaceView+mediaplayer有声音无视频是怎么回事?
- 关于触摸事件和安卓4.0的虚拟按键
- Android2.3开发环境用32位和64位有要求么?
- 关于intent-filter的问题,请教大家
- 关于ListView问题
- 求助:各位android大神们,请帮忙推荐一个关于android系统移植与底层开发的书
- 有没有做Android海外项目的?要注意什么吗?用国外开源代码又要注意什么吗?
- JAVA层进程AIDL 如何使用binder 和c++层的进程通信。C++ 层没有AIDL啊
- android 如何绘制轨迹?
- Android 模拟器唯一标识
- 关于android sdk manager
主布局是一个RelativeLayout,使用inflater+addview加入的LinearLayout属性值
android:layout_alignParentBottom = "true"也是无法起作用,但是将待加入的LinearLayout直接放到主布局中就显示正常
似乎发现问题了,addView(View child)是我调用的函数类型,没有第二个参数。
而且我的inflate方法调用的也是inflate(int resource, ViewGroup root),第二个参数被我设为了null,没有第三个参数。
我刚刚试过将inflate的第二个参数设为主布局RelativeLayout,发现问题解决了,即待加入子布局的属性起作用了。
但是又面临一个新问题,我是通过不同的按钮来切换不同的布局,将不同的布局文件通过inflate+addview方法加入到主布局中。
如果我将所有的inflate方法的第二个参数都设为主布局的话,首先程序启动会直接显示所有的待加入布局,其次再按切换布局按钮就会报错。
我想应该要在按下切换按钮时,动态地设定父布局(我不知道对不对...)。不知道这个想法怎么实施,或者说有其他的解决办法。
调用inflate (int resource, ViewGroup root, boolean attachToRoot) 方法。将第二个参数设为待加入布局的父布局,第三个参数为false