1

在我的应用程序中,用户旋转旋转木马。在选定的项目上,我需要为每个项目显示一个单独的 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:
4

1 回答 1

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);
于 2012-03-08T05:21:31.793 回答