在我的应用中,用户旋转了一个旋转木马。在选定的项目上,我需要为每个项目显示一个单独的 xml View 。旋转木马在底部始终可见, View 在上半部分可见。我认为有比使用 fragment 更好的方法。有任何想法吗?以下代码目前无法正常运行,但我认为充气机可能是可行的方法,但要完成它让我很困扰。 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:
最佳答案
万一其他人遇到这个问题我解决了:
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);
关于android - 显示多个不带 fragment 的 xml View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9522928/