在我的应用中,用户旋转旋转木马。在选定的项目上,我需要为每个项目显示单独的xml视图。转盘在底部始终是可见的,上半部分可见视图。我认为有一种比使用片段更好的方法。有任何想法吗?以下代码现在不起作用,但我认为充气机可能是要走的路,但要完成它是困扰我的。在case0之后有case1-case5。
carousel.setOnItemSelectedListener(new OnItemSelectedListener(){
public void onItemSelected(CarouselAdapter<?> parent, View view,
int position, long id) {
switch(position){
case 0:
final View firstview;
LayoutInflater inflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
firstview = inflater.inflate(R.layout.selected_item, null);
break;
case 1:
答案 0 :(得分:2)
如果有其他人遇到这个问题我解决了它:
LayoutInflater inflater = (LayoutInflater) CarouselActivity.this.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
LinearLayout inflateView = (LinearLayout) findViewById( R.id.InflateParent );
View nextView = null;
switch(position){
case 0:
System.out.println("Case 0");
inflateView.removeAllViews();
nextView = inflater.inflate( R.layout.nextview, null );
inflateView.addView(nextView);