首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >以编程方式在SwipeView中添加新布局

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

Stack Overflow用户
提问于 2011-10-02 21:29:52
回答 1查看 1.5K关注 0票数 1

我会试着用一种非常清晰和容易理解的方式来解释我的问题。

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

代码语言:javascript
复制
<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中以编程方式添加一些布局。

我现在有了:

代码语言:javascript
复制
    SwipeView svmain=(SwipeView) findViewById(R.id.svmain);
    //View v= findViewById(R.layout.anylayout);
    svmain.addView(v);

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

有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-10-02 21:41:13

刚刚找到了答案:

代码语言:javascript
复制
    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);
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7626612

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档