gpt4 book ai didi

android - 如何膨胀FrameLayout?

转载 作者:行者123 更新时间:2023-11-29 02:10:14 53 4
gpt4 key购买 nike

我有线性布局,我想将 FrameLayout 膨胀到其中。你知道怎么做吗?是否可以?我仍然收到 No Suitable Method Found For Inflate

的错误

谢谢

编辑:回答我自己:

LinearLayout ll=(LinearLayout) findViewById(R.id.linear);
final LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
FrameLayout frml = (FrameLayout)inflater.inflate(R.layout.frame,null);
frml.setId(10101010);
frml.setBackgroundColor(Color.RED);

ll.addView(frml);

最佳答案

要获取 LayoutInflater 实例,您需要像这样将其作为服务获取

LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

然后你可以使用它来膨胀 FrameLayout 并像这样将它添加到 LinearLayout

LinearLayout linearLayout = ... ;
inflater.inflate(R.layout.your_framelayout_file_name, linearLayout, false);

并且不要忘记像这样为您的 FrameLayout 设置布局宽度和高度

<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
.
.
.
</FrameLayout>

有关 LayoutInflater 的更多信息 visit this link

关于android - 如何膨胀FrameLayout?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7913496/

53 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com