为什么LayoutInflater不会在我的情况下工作吗?

编程入门 行业动态 更新时间:2024-10-25 13:19:18
本文介绍了为什么LayoutInflater不会在我的情况下工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的 main.xml中布局只包含一个按钮和一个的LinearLayout content_area ,这下图为:

My main.xml layout simply contains a button and a LinearLayout content_area, which shows below:

<LinearLayout xmlns:android="schemas.android/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <LinearLayout android:id="@+id/myBtns" android:layout_width="wrap_content" android:layout_height="fill_parent" android:orientation="horizontal" > <Button android:id="@+id/btn_one" android:layout_width="100dip" android:layout_height="30dip" android:text="button one" /> </LinearLayout> <LinearLayout android:id="@+id/content_area" android:layout_width="fill_parent" android:layout_height="wrap_content" > <!--inflate layout here--> </LinearLayout> </LinearLayout>

我有另一个布局( content_one.xml ),这是怎么回事的情况下使用嵌入(膨胀),以 content_area (id值)在 main.xml中布局:

I have another layout (content_one.xml) which is going to be used to embed(inflate) to content_area(id value) of the main.xml layout:

content_one.xml

<LinearLayout xmlns:android="schemas.android/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <TextView.../> ... <Button .../> </LinearLayout>

我试图用 LayoutInflater 嵌入 content_one.xml 到 content_area 的的main.xml

public class MyActivity extends Activity{ private LinearLayout contentArea; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); contentArea= (LinearLayout) findViewById(R.id.content_area); LayoutInflater inflater = (LayoutInflater)MyActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View inflatedView = (View) inflater.inflate(R.layout.content_one, null); contentArea.addView(inflatedView); }

但它不工作, content_one.xml 在 content_area 不显示的 main.xml中。我在Eclipse中得到了下面的错误信息从LogCat中

But it does not work, content_one.xml does not show in content_area of main.xml . I got the following error message from LogCat in eclipse

(请鼠标右键单击下面的图像和查看图像)

为什么我的LayoutInflater不工作?我在哪里错了?

why my LayoutInflater is not working? Where am I wrong?

推荐答案

的查看正常膨胀,但你有一个 FILL_PARENT 在 myBtns 布局高度,所以其它的LinearLayout是不可见的。如果您将其更改为 WRAP_CONTENT 你可以看到其他的LinearLayout。

The View inflates correctly, but you have a fill_parent height on the myBtns layout, so the other LinearLayout is not visible. If you change it to wrap_content you can see the other LinearLayout.

更多推荐

为什么LayoutInflater不会在我的情况下工作吗?

本文发布于:2023-10-27 22:44:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534769.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:在我   情况下   工作   LayoutInflater

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!