gpt4 book ai didi

android - 以编程方式在 SwipeView 中添加新布局

转载 作者:行者123 更新时间:2023-11-29 18:16:56 24 4
gpt4 key购买 nike

我将尝试以非常清晰易懂的方式解释我的问题。

我目前在这里使用 SwipeView:http://jasonfry.co.uk/?id=23

<uk.co.jasonfry.android.tools.ui.SwipeView  
android:id="@+id/swipe_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View android:id="@+id/view1" />
<View android:id="@+id/view2" />
<View android:id="@+id/view3" />
</uk.co.jasonfry.android.tools.ui.SwipeView>

这很简单也很强大,当然也能正常工作。

我现在想要实现的是在此 SwipeView 中以编程方式添加我的一些 loayouts。

我现在:

    SwipeView svmain=(SwipeView) findViewById(R.id.svmain);
//View v= findViewById(R.layout.anylayout);
svmain.addView(v);

这很崩溃,因为我要添加的 xml 不在我的主布局中。

有什么想法吗?

最佳答案

刚找到答案:

    SwipeView svmain=(SwipeView) findViewById(R.id.svmain);
LayoutInflater inflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.header, null);
svmain.addView(view);
View view2 = inflater.inflate(R.layout.header, null);
svmain.addView(view2);
View view3 = inflater.inflate(R.layout.header, null);
svmain.addView(view3);

关于android - 以编程方式在 SwipeView 中添加新布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7626612/

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