2014-09-25 49 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