1

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

我目前在这里使用 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 中以编程方式添加我的一些布局。

我现在有了:

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

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

任何的想法?

4

1 回答 1

3

刚刚找到答案:

    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);
于 2011-10-02T13:41:12.793 回答