2014-09-25 51 views
0

对不起我的英语。当图片填满屏幕时,我想这样做可以用来滚动。为此,请使用ViewFlipper。但它不起作用。是全屏显示图像的类。我究竟做错了什么?不起作用ViewFlipper

public class FullScreenImage extends Activity implements OnTouchListener{ 
    private ViewFlipper flipper = null; 
    private float fromPosition; 

    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.full_screen); 
     Intent intent = getIntent(); 
     long imageId = intent.getExtras().getLong(FullScreenImage.class.getName()); 

     LinearLayout mainLayout = (LinearLayout) findViewById(R.id.main_layout); 
     flipper = (ViewFlipper) findViewById(R.id.fullImage); 
flipper.setOnTouchListener(this); 
     ImageView imageView = (ImageView) findViewById(R.id.imageView1); 

     imageView.setLayoutParams(new ViewFlipper.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT)); 

     imageView.setImageResource((int) imageId); 


    } 

    public boolean onTouch(View view, MotionEvent event) 
    { 
     switch (event.getAction()) 
     { 
     case MotionEvent.ACTION_DOWN: 
      fromPosition = event.getX(); 
      break; 
     case MotionEvent.ACTION_UP: 
      float toPosition = event.getX(); 
      if (fromPosition > toPosition) 
       flipper.showNext(); 
      else if (fromPosition < toPosition) 
       flipper.showPrevious(); 
     default: 
      break; 
     } 
     return true; 
    } 
} 

xml文件

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/main_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <ViewFlipper 
      android:id="@+id/fullImage" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

    </ViewFlipper> 

</LinearLayout> 

回答

1

你的XML有,但脚蹼中的单个成员。这个想法是有两个或项目和鳍状肢会改变他们之间。像这样的另一个图像添加到您的脚蹼

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/main_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

<ViewFlipper 
     android:id="@+id/fullImage" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 


<ImageView 
    android:id="@+id/imageView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

</ViewFlipper> 

+0

谢谢回答!如何将图片添加到ViewFlipper?这是不行的'flipper.addView(((int)的图像标识,NULL);'这是不是(INT查看不错的选择':ImageAdapter.ThumbsIds){ \t flipper.addView(视图); }'但是我不知道该怎么做 – nesalexy 2014-09-29 18:01:08

+0

我意识到我喜欢这样'for(int i = 0; i nesalexy 2014-09-29 18:22:47