gpt4 book ai didi

android - 在运行时在 android 中重复布局

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:06:59 25 4
gpt4 key购买 nike

我有一个 xml 文件,我想在我的代码中以编程方式重复 RelativeLayout 部分。如何在运行时重复布局?

<?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="match_parent"
android:orientation="vertical" >

<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.11" >

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="39dp"
android:layout_marginTop="26dp"
android:text="Button" />

</RelativeLayout>

</LinearLayout>

最佳答案

LayoutInflater vi = (LayoutInflater) currentContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.id, null);
parentview.add(v);

关于android - 在运行时在 android 中重复布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9394858/

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