First, paste the program running result of this article. The above is the playing/stopping audio, and the progress can be adjusted using SeekBar. below is the playing/stopping video, and the progress is also adjusted using SeekBar:
Source code of main. xml:
The source code of this program is a bit long:
Pack
the View for drawing. The main difference between SurfaceView mode and View mode is that SurfaceView defines a special thread to complete the drawing work. The application does not need to wait for the View to be refreshed, thus improving the performance. The View method is suitable for animations with relatively small processing capacity and low frame rate, such as chess games. The SurfaceView method is mainly used in games and high-quality animations.
To use SurfaceView, follow these steps:
1
to inherit Surfaceview and implement the Surfaceholder.callback interface, which is a surfaceholder internal interface that enables the interface to get information about the changes to the interface, code as follows, and we declare some member variables:
Java code
public class Movementview extends Surfaceview implements Surfaceholder.callback {
private int xpos;
private int yPos;
private int xvel;
private int yvel;
p
The difference between Surfaceview and viewView is in the main thread of the UI that responds directly to the user's actions, as well as the distribution of tasks, but the task is more complex and can become blocked.Surfaceview does not have this problem, assuming that it obtains images directly from memory, and more importantly, Surfaceview can change the UI through threads outside the main thread.UseUpdates to the UI are divided into active and passive updates, and for passive updates, they ar
program enters the background! If the canvas is empty, submit the painting.
A parameter Exception error occurs!
The following is another case: thread startup exception! For example, (simulator error prompt and Logcat Detail)
This exception is only reported when you click the Home button during the program running and enter the program again. The exception indicates that our thread has been started! Why is the return button okay?
OK. Next we will explain in detail the Back and Home butto
To take a photo with the camera step:Call the camera's open () method to turn on the cameras. This method opens the rear-facing camera by default. If you need to turn on the specified camera, you can pass in the camera ID for that method.Call the camera's GetParameters () method to get the camera parameters. The method returns a Camera.parameters objectCall the Camera.parameters object method to set the camera parametersCall the camera's Startpreview () method to start previewing the framing and
Although the previous view is used for plotting, the view plotting mechanism has two defects:
1. Lack of Dual-BUFFER MECHANISM
2. When updating an image, you must update the entire image on the view, which is inefficient.
Therefore, surfaceview is recommended for game plotting. It can only update the specified region to improve efficiency. The following is a simple example to demonstrate the use of surfaceview:
Activity:
Package COM. home. activity; import android. app. activity; import android.
Create a preview class
To allow users to effectively obtain images and videos, they must be able to see images in the camera. A camera preview class is a surfaceview class that can display Real-Time Images in the camera, so users can frame and capture images or videos.
The Code in the following example demonstrates how to create a basic camera preview class that can be included by a viewlayout. This class implements surfaceholder. callback to obtain t
Android uses camera to control the photo taking. It is relatively simple to use camera, and you can proceed with the following steps:
The following is an example:
Activity:
Package COM. home. activity; import Java. io. file; import Java. io. fileoutputstream; import android. app. activity; import android. app. alertdialog; import android. content. context; import android. content. dialoginterface; import android. content. res. configuration; import android. graphics. bitmap; import android. gra
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.