gpt4 book ai didi

android - 将 LinearLayout 添加到 android 中的 LinearLayout

转载 作者:太空宇宙 更新时间:2023-11-03 12:20:40 25 4
gpt4 key购买 nike

我在这里发现了很多关于动态添加 LinearLayout 的问题。我没有找到任何引用资料或任何教程或书籍,我可以在其中了解动态添加 LinearLayout 的完整细节和步骤。

    LinearLayout parentLayout = (LinearLayout) findViewById(R.id.master);
LinearLayout Linear1 = new LinearLayout(this);
Linear1.setOrientation(LinearLayout.HORIZONTAL);
Linear1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
parentLayout.addView(Linear1);

这是我用来添加布局的代码 fragment 。问题是所需的最小 api 是 11。我设计了针对 api 10 的应用程序。所以这对我来说是个坏消息。请告诉我是否有任何其他方法可以为较低的 api 动态添加 LinearLayout

错误消息:调用需要 API 级别 11(当前最低为 8):新的 android.app.ActionBar.LayoutParams

最佳答案

您使用了错误的 LayoutParams 类。使用 LinearLayout.LayoutParams 而不是 ActionBar.LayoutParams

关于android - 将 LinearLayout 添加到 android 中的 LinearLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16868687/

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