2011-10-02 99 views
1

我将尝试以非常清晰易懂的方式解释我的问题。以编程方式在SwipeView中添加新布局

我目前使用的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> 

That'quite简单,功能强大,当然做工精细。

我现在想实现的是在这个SwipeView中编程添加一些loayouts。

我现在有:

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

这是崩溃,因为我要添加的XML是不是在我的主要版面。

有什么想法?

回答

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); 
相关问题