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] รบกวนผู้รู้หน่อยครับ ภาพพื้นหลังไม่ขึ้นครับต้องทำอย่างไร



 

[Android] รบกวนผู้รู้หน่อยครับ ภาพพื้นหลังไม่ขึ้นครับต้องทำอย่างไร

 



Topic : 088448

Guest




http://dl.dropbox.com/u/93608133/com.assignment.DragDrop.DragDrop.rar

ลองโหลด แล้วรันดูครับ
ผมมีข้อสงสัยที่ว่า ผทใส่รูปใน xml ที่เป็นในส่วนของ Background แล้ว
ทีนี้ลองรันดู ภาพก็ไม่ขึ้นครับ ไม่ทราบว่าแก้ไข ในส่วนไหนครับ



Tag : Mobile, Android







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-12-24 07:51:16 By : man View : 1529 Reply : 14
 

 

No. 1



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

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

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

Code ? หรือไม่ลอง Capture มาให้ดูด้วยครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-12-24 09:22:35 By : mr.win
 


 

No. 2

Guest


ได้ครับ
android

อันนี้ส่วน code ครับ

XML
Code (XML)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/fa7"
    android:orientation="vertical" >

<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
</LinearLayout>




ส่วนของ java ColorBall

Code (Android-Java)
package com.assignment.DragDrop;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Point;

public class ColorBall  {
 private Bitmap img; // the image of the ball
 private int coordX = 0; // the x coordinate at the canvas
 private int coordY = 0; // the y coordinate at the canvas
 private int id; // gives every ball his own id, for now not necessary
 private static int count = 1;
 private boolean goRight = true;
 private boolean goDown = true;
 
	public ColorBall(Context context, int drawable) {

		BitmapFactory.Options opts = new BitmapFactory.Options();
        opts.inJustDecodeBounds = true;
        img = BitmapFactory.decodeResource(context.getResources(), drawable); 
        id=count;
		count++;

	}
	
	public ColorBall(Context context, int drawable, Point point) {

		BitmapFactory.Options opts = new BitmapFactory.Options();
        opts.inJustDecodeBounds = true;
        img = BitmapFactory.decodeResource(context.getResources(), drawable); 
        id=count;
		count++;
		coordX= point.x;
		coordY = point.y;

	}
	
	public static int getCount() {
		return count;
	}
	
	void setX(int newValue) {
        coordX = newValue;
    }
	
	public int getX() {
		return coordX;
	}

	void setY(int newValue) {
        coordY = newValue;
   }
	
	public int getY() {
		return coordY;
	}
	
	public int getID() {
		return id;
	}
	
	public Bitmap getBitmap() {
		return img;
	}
	
	public void moveBall(int goX, int goY) {
		// check the borders, and set the direction if a border has reached
		if (coordX > 270){
			goRight = false;
		}
		if (coordX < 0){
			goRight = true;
		}
		if (coordY > 400){
			goDown = false;
		}
		if (coordY < 0){
			goDown = true;
		}
		// move the x and y 
		if (goRight){
			coordX += goX;
		}else
		{
			coordX -= goX;
		}
		if (goDown){
			coordY += goY;
		}else
		{
			coordY -= goY;
		}
		
	}
	
}

ส่วนของ java DragDrop

package com.assignment.DragDrop;

import android.app.Activity;
import android.os.Bundle;

public class  DragDrop extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        // draw the view
        setContentView(new DrawView(this));
        
        
    }
    
}

ส่วนของ java  DrawView 

package com.assignment.DragDrop;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Point;
import android.view.MotionEvent;
import android.view.View;

public class DrawView extends View {
   private ColorBall[] colorballs = new ColorBall[3]; // array that holds the balls
   private int balID = 0; // variable to know what ball is being dragged
    
    public DrawView(Context context) {
        super(context);
        setFocusable(true); //necessary for getting the touch events
        
        // setting the start point for the balls
        Point point1 = new Point();
        point1.x = 50;
        point1.y = 20;
        Point point2 = new Point();
        point2.x = 100;
        point2.y = 20;
        Point point3 = new Point();
        point3.x = 150;
        point3.y = 20;
        
                       
        // declare each ball with the ColorBall class
        colorballs[0] = new ColorBall(context,R.drawable.bol_groen, point1);
        colorballs[1] = new ColorBall(context,R.drawable.bol_rood, point2);
        colorballs[2] = new ColorBall(context,R.drawable.bol_blauw, point3);
        
        
    }
    
    // the method that draws the balls
    @Override protected void onDraw(Canvas canvas) {
        //canvas.drawColor(0xFFCCCCCC);     //if you want another background color       
        
    	//draw the balls on the canvas
    	for (ColorBall ball : colorballs) {
            canvas.drawBitmap(ball.getBitmap(), ball.getX(), ball.getY(), null);
          }

    }
    
    // events when touching the screen
    public boolean onTouchEvent(MotionEvent event) {
        int eventaction = event.getAction(); 
        
        int X = (int)event.getX(); 
        int Y = (int)event.getY(); 

        switch (eventaction ) { 

        case MotionEvent.ACTION_DOWN: // touch down so check if the finger is on a ball
        	balID = 0;
        	for (ColorBall ball : colorballs) {
        		// check if inside the bounds of the ball (circle)
        		// get the center for the ball
        		int centerX = ball.getX() + 25;
        		int centerY = ball.getY() + 25;
        		
        		// calculate the radius from the touch to the center of the ball
        		double radCircle  = Math.sqrt( (double) (((centerX-X)*(centerX-X)) + (centerY-Y)*(centerY-Y)));
        		
        		// if the radius is smaller then 23 (radius of a ball is 22), then it must be on the ball
        		if (radCircle < 23){
        			balID = ball.getID();
                    break;
        		}

        		// check all the bounds of the ball (square)
        		//if (X > ball.getX() && X < ball.getX()+50 && Y > ball.getY() && Y < ball.getY()+50){
                //	balID = ball.getID();
                //	break;
                //}
              }
             
             break; 


        case MotionEvent.ACTION_MOVE:   // touch drag with the ball
        	// move the balls the same as the finger
            if (balID > 0) {
            	colorballs[balID-1].setX(X-25);
            	colorballs[balID-1].setY(Y-25);
            }
        	
            break; 

        case MotionEvent.ACTION_UP: 
       		// touch drop - just do things here after dropping

             break; 
        } 
        // redraw the canvas
        invalidate(); 
        return true; 
	
    }
}

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-12-24 21:04:01 By : man
 

 

No. 3

Guest


ตอบความคิดเห็นที่ : 2 เขียนโดย : man เมื่อวันที่ 2012-12-24 21:04:01
รายละเอียดของการตอบ ::

"setContentView(new DrawView(this));" ---> ที่มันไม่ขึ้นเพราะว่า ไม่ได้ เรียก layout .xml ครับ

วิธีแก้ (ผมยังไม่ได้ลอง นะครับว่าได้ หรือไม่ได้ แต่น่าจะได้ครับ)


setContentView( R.layout."ชื่อ layout" );

LinearLayout llParent = (LinearLayout)findViewById( R.id."linearlayout ใน file xml " );

DrawView ballView = new DrawView(this);
llParent.addView( ballView );

ประมาณนี้ ครับ สงสัยอะไรถามได้ ครับ


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-12-26 17:25:44 By : alek_sg
 


 

No. 4

Guest


พี่ครับ มัน ERROR อะครับ ต้องแก้ยังไงดีครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-12-26 19:31:36 By : man
 


 

No. 5

Guest


ตอบความคิดเห็นที่ : 4 เขียนโดย : man เมื่อวันที่ 2012-12-26 19:31:36
รายละเอียดของการตอบ ::
ขอดู code กับ log cat หน่อยครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-12-27 11:53:09 By : alek
 


 

No. 6

Guest


โค้ดที่เพิ่มเติมหรือเปล่าครับ

Code (Android-Java)
package com.assignment.DragDrop;

import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;

public class  DragDrop extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        // draw the view
        setContentView(new DrawView(this));
        setContentView(R.layout.main);
        DrawView ballView = new DrawView(this);
        LinearLayout llParent = (LinearLayout)findViewById(R.layout.main);
        llParent.addView( ballView );
     
       
        
    }
    
}



log
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-12-27 15:08:13 By : man
 


 

No. 7

Guest


โค้ดที่เพิ่มเติมหรือเปล่าครับ

Code (Android-Java)
package com.assignment.DragDrop;

import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;

public class  DragDrop extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        // draw the view
       
        setContentView(R.layout.main);
        DrawView ballView = new DrawView(this);
        LinearLayout llParent = (LinearLayout)findViewById(R.layout.main);
        llParent.addView( ballView );
     
       
        
    }
    
}



log
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-12-27 15:21:56 By : man
 


 

No. 8

Guest


ตอบความคิดเห็นที่ : 6 เขียนโดย : man เมื่อวันที่ 2012-12-27 15:08:13
รายละเอียดของการตอบ ::

Code (Android-Java)
setContentView(new DrawView(this)); 
setContentView(R.layout.main);
DrawView ballView = new DrawView(this);
LinearLayout llParent = (LinearLayout)findViewById(R.layout.main);
llParent.addView( ballView );




แก้เป็น

ส่วนของ mail.xml
Code (XML)
<?xml version="1.0" encoding="utf-8"?>
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:id="@id/linearlayout1" --------> เพิ่มบรรทัดนี้ใน main.xml
             android:layout_width="fill_parent"
             android:layout_height="fill_parent"
             android:background="@drawable/fa7"
             android:orientation="vertical" >

             <TextView 
                     android:layout_width="fill_parent"
                     android:layout_height="wrap_content"
                     android:text="@string/hello"
/>


ส่วนของ code

Code (Android-Java)
setContentView(R.layout.main);
DrawView ballView = new DrawView(this);
LinearLayout llParent = (LinearLayout)findViewById(R.id.linearlayout1);
llParent.addView( ballView );


คอนเซ็บป์ คือ เนื่องจาก class DrawView extends มาจาก view เพราะฉะนั้น จึงต้อง add ลง lineralayout เพราะว่า linearlayout สามารถเพิ่ม view ได้ ดังนั้น DrawView เป็น view จึงสามารถ addview ลง LinearLayout ได้


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-12-27 15:22:07 By : alek
 


 

No. 9

Guest


setContentView(new DrawView(this));
llParent.addView( ballView );

พอเอา 2 อันนี้ออก ภาพพื้นหลังขึ้นครับ
แต่ลูกบอลหายไปครับ ทำยังไงดีครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-12-27 15:27:21 By : man
 


 

No. 10

Guest


http://www.upload-thai.com/download.php?id=2944d42ee5462b0712b9e57bf23df441

ลอง download ไปดูครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-12-27 15:58:57 By : alek
 


 

No. 11

Guest


ขอบคุณมากๆเลยครับ
แล้วที่ผมทำ error มันเกิดจากอะไรหรือครับ
อีกเรื่องที่อยากรบกวนสอบถามครับ รับเป็นที่ปรึกษาโปรเจคหรือเปล่าครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-12-27 17:18:31 By : man
 


 

No. 12

Guest


ถามต่อครับ ทำให้มัน full screen ยังไงครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-12-27 17:40:38 By : man
 


 

No. 13

Guest


ตอบความคิดเห็นที่ : 12 เขียนโดย : man เมื่อวันที่ 2012-12-27 17:40:38
รายละเอียดของการตอบ ::

ใส่ที่ oncreate ครับ
getWindow().requestFeature(Window.FEATURE_NO_TITLE);

ที่น้องทำแล้ว error เพราะ
1.อ้างอิงผิด ครับ
LinearLayout llParent = (LinearLayout)findViewById(R.layout.main); --> น้องเอา R.layout.main ไม่ได้ครับ เพราะนี้เป็นการดึง linearlayout จากโฟเดอร์ layout file main.xml มันก็เลย error ครับ



แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-01-02 13:46:10 By : alek
 


 

No. 14

Guest


ขอบคุณครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-01-07 15:43:24 By : man
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : [Android] รบกวนผู้รู้หน่อยครับ ภาพพื้นหลังไม่ขึ้นครับต้องทำอย่างไร
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 00
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 อัตราราคา คลิกที่นี่