2014-09-25 1 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이있다

하지만 플리퍼 내에서 단일 멤버. 아이디어는 2 개 또는 항목을 가지며 플리퍼가 그들 사이에서 변경됩니다. 대답을 당신의 지느러미에

<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에 사진을 추가하려면 어떻게해야합니까? 이것은 flippper.addView ((int) imageId, null); 그리고 이것은 (int view : ImageAdapter.ThumbsIds) { \t flipper.addView (view); }'에 대해서는 좋지 않은 옵션입니다. – nesalexy

+0

나는 이것을 (int i = 0; i nesalexy

관련 문제