2011-11-30 5 views

答えて

1

XML:(design.xml)

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> 
    <FrameLayout android:layout_width="90px" android:layout_height="90px"> 
    <RelativeLayout android:id="@+id/container" android:layout_width="fill_parent" android:layout_height="fill_parent">   
    </RelativeLayout> 
</FrameLayout> 
</FrameLayout> 

Javaコード:

public class Example extends Activity { 
    private RelativeLayout container; 
    private int currentX; 
    private int currentY; 

    protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.design); 

    container = (RelativeLayout)findViewById(R.id.container); 

    int top = 0; 
    int left = 0; 

    ImageView image1 = ... 
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); 
    layoutParams.setMargins(left, top, 0, 0);    
    container.addView(image1, layoutParams); 

    ImageView image2 = ... 
    left+= 100; 
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); 
    layoutParams.setMargins(left, top, 0, 0);    
    container.addView(image2, layoutParams); 

    ImageView image3 = ... 
    left= 0; 
    top+= 100; 
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); 
    layoutParams.setMargins(left, top, 0, 0);    
    container.addView(image3, layoutParams); 

    ImageView image4 = ... 
    left+= 100;  
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); 
    layoutParams.setMargins(left, top, 0, 0);    
    container.addView(image4, layoutParams); 
    }  

    @Override 
    public boolean onTouchEvent(MotionEvent event) { 
    switch (event.getAction()) { 
     case MotionEvent.ACTION_DOWN: { 
      currentX = (int) event.getRawX(); 
      currentY = (int) event.getRawY(); 
      break; 
     } 

     case MotionEvent.ACTION_MOVE: { 
      int x2 = (int) event.getRawX(); 
      int y2 = (int) event.getRawY(); 
      container.scrollBy(currentX - x2 , currentY - y2); 
      currentX = x2; 
      currentY = y2; 
      break; 
     } 
     case MotionEvent.ACTION_UP: { 
      break; 
     } 
    } 
     return true; 
    } 
} 

希望これは、私は、出力のために何かを得ていないのです

+0

...あなたを助けます... – Karthik

関連する問題