我会试着用一种非常清晰和容易理解的方式来解释我的问题。
我目前在这里使用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不在我的主布局中。
有什么想法吗?
发布于 2011-10-02 21:41:13
刚刚找到了答案:
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);https://stackoverflow.com/questions/7626612
复制相似问题