Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > Mobile > Mobile Forum > Android - ช่วยแก้โค้ด DragEvent หน่อยค่ะ เราควรเช็คยังไงดีค่ะให้รับแค่ภาพเดียว และรูปอื่นไม่หายไปค่ะ



 

Android - ช่วยแก้โค้ด DragEvent หน่อยค่ะ เราควรเช็คยังไงดีค่ะให้รับแค่ภาพเดียว และรูปอื่นไม่หายไปค่ะ

 



Topic : 103125

Guest




ต้องการให้ภาพแมวเพียงถาพเดียวไปแทนในตำแหน่งเครื่องหมายคำถาม ส่วนรูปอื่นกลับไปยังตำแหน่งเดิม จะแก้โค้ดตรงไหนค่ะ

งานCode (Android-Java)

Activity.xml
Code (Android-Java)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/bggame" >

    <ImageButton
        android:id="@+id/btcat"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="376dp"
        android:layout_marginTop="35dp"
        android:src="@drawable/btcat" />

    <RelativeLayout
        android:id="@+id/bottomright"
        android:layout_width="150dp"
        android:layout_height="120dp"
        android:layout_alignLeft="@+id/btcat"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="41dp"
        android:layout_marginLeft="63dp"
        android:background="@drawable/slot" >
    </RelativeLayout>

        <ImageView
            android:id="@+id/ivcat"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/btcat"
            android:layout_marginRight="119dp"
            android:layout_marginTop="26dp"
            android:layout_toLeftOf="@+id/btcat"
            android:src="@drawable/cat" />

        <ImageView
            android:id="@+id/ivbutterfly"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignRight="@+id/btcat"
            android:layout_alignTop="@+id/ivcat"
            android:layout_marginRight="95dp"
            android:src="@drawable/butterfly" />

        <ImageView
            android:id="@+id/ivbuffalo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/bottomright"
            android:layout_alignTop="@+id/ivbutterfly"
            android:layout_marginLeft="65dp"
            android:src="@drawable/buffalo" />

        <ImageView
            android:id="@+id/ivbird"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/ivbuffalo"
            android:layout_marginLeft="42dp"
            android:layout_toRightOf="@+id/ivbuffalo"
            android:src="@drawable/bird" />
    
</RelativeLayout>


MainActivity.java
Code (Android-Java)
package com.example.test;

import android.app.Activity;
import android.content.ClipData;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.DragEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.DragShadowBuilder;
import android.view.View.OnDragListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

public class MainActivity extends Activity {
  
/** Called when the activity is first created. */

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    findViewById(R.id.ivbird).setOnTouchListener(new MyTouchListener());
    findViewById(R.id.ivbuffalo).setOnTouchListener(new MyTouchListener());
    findViewById(R.id.ivbutterfly).setOnTouchListener(new MyTouchListener());
    findViewById(R.id.ivcat).setOnTouchListener(new MyTouchListener());
    //findViewById(R.id.slot).setOnDragListener(new MyDragListener());
    //findViewById(R.id.topright).setOnDragListener(new MyDragListener());
    //findViewById(R.id.bottomleft).setOnDragListener(new MyDragListener());
    findViewById(R.id.bottomright).setOnDragListener(new MyDragListener());

  }

  private final class MyTouchListener implements OnTouchListener {
    public boolean onTouch(View view, MotionEvent motionEvent) {
      if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
        ClipData data = ClipData.newPlainText("", "");
        DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
        view.startDrag(data, shadowBuilder, view, 0);
        view.setVisibility(View.INVISIBLE);
        return true;
      } else {
        return false;
      }
    }
  }

  class MyDragListener implements OnDragListener {
    Drawable enterShape = getResources().getDrawable(R.drawable.black);
    Drawable normalShape = getResources().getDrawable(R.drawable.slot);
    

    @Override
    public boolean onDrag(View v, DragEvent event) {
      int action = event.getAction();
      View dropd = (View) v;
      switch (event.getAction()) {
      case DragEvent.ACTION_DRAG_STARTED:
        // do nothing
        break;
      case DragEvent.ACTION_DRAG_ENTERED:
        v.setBackgroundDrawable(enterShape);
        break;
      case DragEvent.ACTION_DRAG_EXITED:
        v.setBackgroundDrawable(normalShape);
        break;
      case DragEvent.ACTION_DROP:
        // Dropped, reassign View to ViewGroup
        View view = (View) event.getLocalState();
        ViewGroup owner = (ViewGroup) view.getParent();
        owner.removeView(view);
        RelativeLayout container = (RelativeLayout) v;
        container.addView(view);
        view.setVisibility(View.VISIBLE);
        break;
      	case DragEvent.ACTION_DRAG_ENDED:
        v.setBackgroundDrawable(normalShape);
      default:
        break;
      }
      return true;
    }
  }
} 




Tag : Mobile, Android







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-11-27 14:31:17 By : ducth_mill View : 988 Reply : 2
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Quote:
case DragEvent.ACTION_DRAG_ENTERED:
v.setBackgroundDrawable(enterShape);
break;


น่าจะเขียนเงื่อนไขตรวจสอบในนี้หรือเปล่าครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-11-28 06:11:09 By : mr.win
 


 

No. 2

Guest


เขียนไงหรอค่ะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-11-28 12:43:10 By : ducth_mill
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : Android - ช่วยแก้โค้ด DragEvent หน่อยค่ะ เราควรเช็คยังไงดีค่ะให้รับแค่ภาพเดียว และรูปอื่นไม่หายไปค่ะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 04
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่