当前位置: 编程技术>移动开发
本页文章导读:
▪怎么去掉Spinner旁边的按钮 如何去掉Spinner旁边的按钮
import android.app.Activity;import android.content.Context;import android.os.Bundle;import android.widget.ArrayAdapter;import android.widget.Spinner;import android.widget.SpinnerAdapter;public class MySpinner ext.........
▪ 让背景动前途不动 ViewFlipper的用法 让背景动前景不动 ViewFlipper的用法
其实呢这个实例没有多大用处,代码也简单只是看看当图片作为背景的时候 能不能也动画出来 结果是可以的ViewFlipper mFlipper = new ViewFlipper(this); .........
▪ 手机照相加入相关信息说明 手机拍照加入相关信息说明
Button imagecapture = (Button)findViewById(R.id.imagecapture); imagecapture.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { .........
[1]怎么去掉Spinner旁边的按钮
来源: 互联网 发布时间: 2014-02-18
如何去掉Spinner旁边的按钮
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
public class MySpinner extends Activity { //data that will be used as a spinner options
private static String data[] = {"one", "two", "three"}; /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//main.xml file contains spinner
setContentView(R.layout.main);
Spinner spinner = (Spinner) findViewById(R.id.spinner);
//create your own adapter
MySpinnerAdapter adapter = new MySpinnerAdapter(this,R.layout.custom_spinner_row,R.id.text, data );
//set your custom adapter
spinner.setAdapter( adapter );
}
private class MySpinnerAdapter extends ArrayAdapter
{
public MySpinnerAdapter(Context context, int resource, int textViewResourceId, String[] objects)
{ super(context, resource, textViewResourceId, objects);
}
}
R.layout.custom_spinner_row是只含有一个linear并包含一个叫text的文本框
如果你想做的更好看些 ,那你还的重写 getView() method
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
public class MySpinner extends Activity { //data that will be used as a spinner options
private static String data[] = {"one", "two", "three"}; /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//main.xml file contains spinner
setContentView(R.layout.main);
Spinner spinner = (Spinner) findViewById(R.id.spinner);
//create your own adapter
MySpinnerAdapter adapter = new MySpinnerAdapter(this,R.layout.custom_spinner_row,R.id.text, data );
//set your custom adapter
spinner.setAdapter( adapter );
}
private class MySpinnerAdapter extends ArrayAdapter
{
public MySpinnerAdapter(Context context, int resource, int textViewResourceId, String[] objects)
{ super(context, resource, textViewResourceId, objects);
}
}
R.layout.custom_spinner_row是只含有一个linear并包含一个叫text的文本框
如果你想做的更好看些 ,那你还的重写 getView() method
[2] 让背景动前途不动 ViewFlipper的用法
来源: 互联网 发布时间: 2014-02-18
让背景动前景不动 ViewFlipper的用法
其实呢这个实例没有多大用处,代码也简单只是看看当图片作为背景的时候 能不能也动画出来 结果是可以的
ViewFlipper mFlipper = new ViewFlipper(this);
ImageView i = new ImageView(this);
i.setBackgroundDrawable(getResources().getDrawable(R.drawable.icon));
i.setImageResource(R.drawable.android_waving);
ImageView i2 = new ImageView(this);
i2.setBackgroundDrawable(getResources().getDrawable(R.drawable.xb));
i2.setImageResource(R.drawable.android_waving);
mFlipper.setInAnimation(AnimationUtils.loadAnimation(this,android.R.anim.fade_in));
mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this,android.R.anim.fade_out));
mFlipper.addView(i);
mFlipper.addView(i2);
mFlipper.startFlipping();
setContentView(mFlipper);
通常我们不需要把要动画的图片作为背景用 i.setBackgroundDrawable而是用i.setImageResource,这个例子只是为了验证一下背景是不是可以动。
其实呢这个实例没有多大用处,代码也简单只是看看当图片作为背景的时候 能不能也动画出来 结果是可以的
ViewFlipper mFlipper = new ViewFlipper(this);
ImageView i = new ImageView(this);
i.setBackgroundDrawable(getResources().getDrawable(R.drawable.icon));
i.setImageResource(R.drawable.android_waving);
ImageView i2 = new ImageView(this);
i2.setBackgroundDrawable(getResources().getDrawable(R.drawable.xb));
i2.setImageResource(R.drawable.android_waving);
mFlipper.setInAnimation(AnimationUtils.loadAnimation(this,android.R.anim.fade_in));
mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this,android.R.anim.fade_out));
mFlipper.addView(i);
mFlipper.addView(i2);
mFlipper.startFlipping();
setContentView(mFlipper);
通常我们不需要把要动画的图片作为背景用 i.setBackgroundDrawable而是用i.setImageResource,这个例子只是为了验证一下背景是不是可以动。
[3] 手机照相加入相关信息说明
来源: 互联网 发布时间: 2014-02-18
手机拍照加入相关信息说明
Button imagecapture = (Button)findViewById(R.id.imagecapture);
imagecapture.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String filename = null;
ImageCaptureCallback iccb = null;
try {
filename = timeStampFormat.format(new Date());
ContentValues values = new ContentValues();
values.put(Media.TITLE, filename);
values.put(Media.DESCRIPTION, "Image capture by camera");
Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
iccb = new ImageCaptureCallback( getContentResolver().openOutputStream(uri));
} catch(Exception ex ){
ex.printStackTrace();
Log.e(getClass().getSimpleName(), ex.getMessage(), ex);
}
camera.takePicture(mShutterCallback, mPictureCallbackRaw, iccb);
com.froogloid.android.gspot.Park.imageFileName = filename;
}
});
private OutputStream filoutputStream;
public ImageCaptureCallback(OutputStream filoutputStream) {
this.filoutputStream = filoutputStream;
}
@Override
public void onPictureTaken(byte[] data, Camera camera) {
try {
Log.v(getClass().getSimpleName(), "onPictureTaken=" + data + " length = " + data.length);
FileOutputStream buf = new FileOutputStream("/sdcard/dcim/Camera/" + CameraActivity.filename + ".jpg");
buf.write(data);
buf.flush();
buf.close();
// filoutputStream.write(data);
filoutputStream.flush();
filoutputStream.close();
} catch(Exception ex) {
ex.printStackTrace();
}
}
}
主要是这几句的使用
ContentValues values = new ContentValues();
values.put(Media.TITLE, filename);
values.put(Media.DESCRIPTION, "Image capture by camera");
Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
Button imagecapture = (Button)findViewById(R.id.imagecapture);
imagecapture.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String filename = null;
ImageCaptureCallback iccb = null;
try {
filename = timeStampFormat.format(new Date());
ContentValues values = new ContentValues();
values.put(Media.TITLE, filename);
values.put(Media.DESCRIPTION, "Image capture by camera");
Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
iccb = new ImageCaptureCallback( getContentResolver().openOutputStream(uri));
} catch(Exception ex ){
ex.printStackTrace();
Log.e(getClass().getSimpleName(), ex.getMessage(), ex);
}
camera.takePicture(mShutterCallback, mPictureCallbackRaw, iccb);
com.froogloid.android.gspot.Park.imageFileName = filename;
}
});
private OutputStream filoutputStream;
public ImageCaptureCallback(OutputStream filoutputStream) {
this.filoutputStream = filoutputStream;
}
@Override
public void onPictureTaken(byte[] data, Camera camera) {
try {
Log.v(getClass().getSimpleName(), "onPictureTaken=" + data + " length = " + data.length);
FileOutputStream buf = new FileOutputStream("/sdcard/dcim/Camera/" + CameraActivity.filename + ".jpg");
buf.write(data);
buf.flush();
buf.close();
// filoutputStream.write(data);
filoutputStream.flush();
filoutputStream.close();
} catch(Exception ex) {
ex.printStackTrace();
}
}
}
主要是这几句的使用
ContentValues values = new ContentValues();
values.put(Media.TITLE, filename);
values.put(Media.DESCRIPTION, "Image capture by camera");
Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
最新技术文章: