2014-11-21 1 views
0
내가이 장면을 구현해야

사이에 이미지를 이동,하지만 난 그것을 접근하는 방법을 모른다 :안드로이드 :있는 GridViews

gridview

검은 색 사각형이 개있는 GridViews는, 블루 광장 이미지의은 빨간색 하나는 자리 표시자를 표시하기위한 것입니다).

gridviews 사이에서 이미지를 드래그하여 사용자가 4-5 개의 이미지 (빨간색 사각형으로 표시)를 선택할 수 있도록해야합니다. 위에서 아래로 그리고 위에서 아래로 (선택 및 선택 취소) 드래그하십시오. 누구든지 나를 도울 수 있습니까 ??

답변

0

귀하의 활동에 OnTouchListener 및 OnDragListener를 구현하면 쉽게 수행 할 수 있습니다. 이전에 shape_droptarget.xml 및 shape.xml을 드로어 블 폴더에 만듭니다. 내 작업을 위해 구현했습니다. 나는 당신에게 도움이되기를 바랍니다.

shape_droptarget.xml

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" > 

    <stroke 
     android:width="2dp" 
     android:color="#FFFF0000" /> 

    <gradient 
     android:angle="225" 
     android:endColor="#DD2ECCFA" 
     android:startColor="#DD000000" /> 

    <corners 
     android:bottomLeftRadius="7dp" 
     android:bottomRightRadius="7dp" 
     android:topLeftRadius="7dp" 
     android:topRightRadius="7dp" /> 

</shape> 

shape.xml

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" > 

    <stroke 
     android:width="2dp" 
     android:color="#FFFFFFFF" /> 

    <gradient 
     android:angle="225" 
     android:endColor="#DD2ECCFA" 
     android:startColor="#DD000000" /> 

    <corners 
     android:bottomLeftRadius="7dp" 
     android:bottomRightRadius="7dp" 
     android:topLeftRadius="7dp" 
     android:topRightRadius="7dp" /> 

</shape> 

생성 활동 DragActivity 레이아웃 폴더

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

    <GridLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/darkred" 
     android:columnCount="2" 
     android:columnWidth="300dp" 
     android:orientation="vertical" 
     android:rowCount="2" 
     android:stretchMode="columnWidth" > 

    <LinearLayout 
     android:id="@+id/topleft" 
     android:layout_width="160dp" 
     android:layout_height="200dp" 
     android:layout_column="0" 
     android:layout_row="0" 
     android:background="@drawable/shape" > 

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

      android:src="@drawable/ic_launcher" /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/topright" 
     android:layout_width="160dp" 
     android:layout_height="200dp" 
     android:layout_column="1" 
     android:layout_row="0" 
     android:background="@drawable/shape" > 

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

      android:src="@drawable/ic_launcher" /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/bottomleft" 
     android:layout_width="160dp" 
     android:layout_height="200dp" 
     android:layout_column="0" 
     android:layout_row="1" 
     android:background="@drawable/shape" > 

     <ImageView 
      android:id="@+id/myimage3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/ic_launcher" /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/bottomright" 
     android:layout_width="160dp" 
     android:layout_height="200dp" 
     android:layout_column="1" 
     android:layout_row="1" 
     android:background="@drawable/shape" > 

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

      android:src="@drawable/ic_launcher" /> 
    </LinearLayout> 

</GridLayout> 
    <View 
     android:layout_width="match_parent" 
     android:layout_height="100dp" 
    > 
    </View> 
    <GridLayout 
     android:background="@color/darkgreen" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:columnCount="4" 
    android:columnWidth="300dp" 
    android:orientation="horizontal" 
    android:rowCount="1" 
    android:stretchMode="columnWidth" > 

    <LinearLayout 
     android:id="@+id/topleft1" 
     android:layout_width="160dp" 
     android:layout_height="200dp" 
     android:layout_column="0" 
     android:layout_row="0" 
     android:background="@drawable/shape" > 

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

      android:src="@drawable/ic_launcher" /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/topright1" 
     android:layout_width="160dp" 
     android:layout_height="200dp" 
     android:layout_column="1" 
     android:layout_row="0" 
     android:background="@drawable/shape" > 

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

      android:src="@drawable/ic_launcher" /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/bottomleft1" 
     android:layout_width="160dp" 
     android:layout_height="200dp" 
     android:layout_column="2" 
     android:layout_row="0" 
     android:background="@drawable/shape" > 

     <ImageView 
      android:id="@+id/myimage31" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/ic_launcher" /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/bottomright1" 
     android:layout_width="160dp" 
     android:layout_height="200dp" 
     android:layout_column="3" 
     android:layout_row="0" 
     android:background="@drawable/shape" > 

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

      android:src="@drawable/ic_launcher" /> 
    </LinearLayout> 

</GridLayout> 
</LinearLayout> 

draglayout.xml에 파일을 생성

이제 한 그리드에서 다른 그리드로 이미지를 이동할 수 있습니다.

+0

네,하지만 이미지를 드래그하면 이미지가 드래그 될 때 (예 : 중복 된 것처럼) 이전 위치에도 똑같이 남아 있습니다. –

+0

이미지가 포인터로 움직이며 포인터로 움직입니다. 당신은 정확하게하고 싶지. 또한 당신의 요구 사항으로 자체 컨테이너에서 움직여서는 안되기 때문에 이미지 뷰의 높이와 너비를 부모와 동일하게 설정할 수 있습니다. XML 파일에서 두 번째 눈금의 이미지 뷰에서 android : src를 제거하십시오. –

관련 문제