2011-10-02 94 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); 
相關問題