android相册功能
㈠ Android 微信里---我---相册,这个功能,布局怎么写代码怎么写请大神解答
1、布局:一个ListView,里头放些个textVIEW显示时间。一个gridVIEW用来显示相片。没有相片gridview的adapter就提供一个默认图片给它显示 后面一个textview显示张数,那个雨是标题的话也来个textview显示,没有数据那些textview就都为空或者设为gone。
2、代码:gridview显示的那些照片用bitmap缩放一下是要的。其他的感觉没什么特别的。
㈡ Android中如何实现图片的放大功能(手机相册里的那种效果)
你是要代码实现还是操作?
要代码我有源代码。要是操作上的问题那就是我理解错你问题了。
/* import相关class */
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
public class EX04_23 extends Activity
{
/* 相关变量声明 */
private ImageView mImageView;
private Button mButton01;
private Button mButton02;
private RelativeLayout layout1;
private Bitmap bmp;
private int id=0;
private int displayWidth;
private int displayHeight;
private float scaleWidth=1;
private float scaleHeight=1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
/* 加载main.xml Layout */
setContentView(R.layout.main);
/* 取得屏幕分辨率大小 */
DisplayMetrics dm=new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
displayWidth=dm.widthPixels;
/* 屏幕高度须扣除下方Button高度 */
displayHeight=dm.heightPixels-80;
/* 初始化相关变量 */
bmp=BitmapFactory.decodeResource(getResources(),R.drawable.ex04_23);
mImageView = (ImageView)findViewById(R.id.myImageView);
layout1 = (RelativeLayout)findViewById(R.id.layout1);
mButton01 = (Button)findViewById(R.id.myButton1);
mButton02 = (Button)findViewById(R.id.myButton2);
/* 缩小按钮onClickListener */
mButton01.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View v)
{
small();
}
});
/* 放大按钮onClickListener */
mButton02.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View v)
{
big();
}
});
}
/* 图片缩小的method */
private void small()
{
int bmpWidth=bmp.getWidth();
int bmpHeight=bmp.getHeight();
/* 设定图片缩小的比例 */
double scale=0.8;
/* 计算出这次要缩小的比例 */
scaleWidth=(float) (scaleWidth*scale);
scaleHeight=(float) (scaleHeight*scale);
/* 生成reSize后的Bitmap对象 */
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
Bitmap resizeBmp = Bitmap.createBitmap(bmp,0,0,bmpWidth,bmpHeight,matrix,true);
if(id==0)
{
/* 如果是第一次按,就移除原来设定的ImageView */
layout1.removeView(mImageView);
}
else
{
/* 如果不是第一次按,就移除上次放大缩小所生成的ImageView */
layout1.removeView((ImageView)findViewById(id));
}
/* 产生新的ImageView,放入reSize的Bitmap对象,再放入Layout中 */
id++;
ImageView imageView = new ImageView(EX04_23.this);
imageView.setId(id);
imageView.setImageBitmap(resizeBmp);
layout1.addView(imageView);
setContentView(layout1);
/* 因为图片放到最大时放大按钮会disable,所以在缩小时把他重设为enable */
mButton02.setEnabled(true);
}
/* 图片放大的method */
private void big()
{
int bmpWidth=bmp.getWidth();
int bmpHeight=bmp.getHeight();
/* 设定图片放大的比例 */
double scale=1.25;
/* 计算这次要放大的比例 */
scaleWidth=(float)(scaleWidth*scale);
scaleHeight=(float)(scaleHeight*scale);
/* 产生reSize后的Bitmap对象 */
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
Bitmap resizeBmp = Bitmap.createBitmap(bmp,0,0,bmpWidth,bmpHeight,matrix,true);
if(id==0)
{
/* 如果是第一次按,就移除原来设定的ImageView */
layout1.removeView(mImageView);
}
else
{
/* 如果不是第一次按,就移除上次放大缩小所生成的ImageView */
layout1.removeView((ImageView)findViewById(id));
}
/* 产生新的ImageView,放入reSize的Bitmap对象,再放入Layout中 */
id++;
ImageView imageView = new ImageView(EX04_23.this);
imageView.setId(id);
imageView.setImageBitmap(resizeBmp);
layout1.addView(imageView);
setContentView(layout1);
/* 如果再放大会超过屏幕大小,就把Button disable */
if(scaleWidth*scale*bmpWidth>displayWidth||scaleHeight*scale*bmpHeight>displayHeight)
{
mButton02.setEnabled(false);
}
}
}
㈢ Android制作一个相册
这是我学习Android时做的一个小程序,程序主要功能是实现一个迷你相册的功能,可以在虚拟机上看到很不错的效果。
我设置屏幕的大小为800*600
/*
*ImageSwitcherGallery.java
*/
package android.study_layout;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.animation.AnimationUtils;
import android.widget.*;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ViewSwitcher.ViewFactory;
public class ImageSwitcherGallery extends Activity implements
OnItemSelectedListener, ViewFactory {
private ImageSwitcher image_switcher;
private Gallery gallery;
private Integer[] mThumbIds = { R.drawable.a1, R.drawable.a2,
R.drawable.a3, R.drawable.a4, R.drawable.a5,
};
private Integer[] mImageIds = { R.drawable.a1, R.drawable.a2,
R.drawable.a3, R.drawable.a4, R.drawable.a5, };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.image_switcher_gallery);
image_switcher = (ImageSwitcher) findViewById(R.id.switcher);
image_switcher.setFactory(this);
image_switcher.setInAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_in));
image_switcher.setOutAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_out));
gallery = (Gallery) findViewById(R.id.gallery);
gallery.setAdapter(new ImageAdapter(this));
gallery.setOnItemSelectedListener(this);
}
@Override
public View makeView() {
ImageView image = new ImageView(this);
image.setBackgroundColor(0xFF000000);
image.setScaleType(ImageView.ScaleType.FIT_XY);
image.setLayoutParams(new ImageSwitcher.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
return image;
}
public class ImageAdapter extends BaseAdapter {
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView image = new ImageView(mContext);
image.setImageResource(mThumbIds[position]);
image.setAdjustViewBounds(true);
image.setLayoutParams(new Gallery.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
return image;
}
private Context mContext;
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position,
long id) {
ImageSwitcher image_switcher = (ImageSwitcher) findViewById(R.id.switcher);
image_switcher.setImageResource(mImageIds[position]);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
}
xml文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageSwitcher
android:id="@+id/switcher"
android:layout_width="match_parent"
android:layout_height="450dip"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
/>
<Gallery
android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_height="120dip"
android:background="#55000000"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:gravity="center_vertical"
android:spacing="30dip"
/>
</RelativeLayout>
㈣ 如何 android 编程 相册
简单介绍一下如何在界面上实现图片显示。
方法/步骤
先做一张图片,打开画图软件,用画笔在上面写上“你好”,然后直接保存到一个安卓工程的res/drawable_hdpi文件夹下。
在activity_main.xml下写入一下代码:
<?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">
<ImageView
android:id="@+id/imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/hello"/>
</LinearLayout
在mainactivite.java下写入一下代码:
package com.ddexample.dh1;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
最后直接运行这个安卓工程,就可以直接显示刚才制作的图片了。
http://jingyan..com/article/49711c6153a277fa441b7cf4.html
㈤ android相册里会显示出很多缓存以及隐私图片,请问如何不让他预览出来!
有一种办法可以让他在系统图片查看器还是第三方看图软件里都读不出该文件夹下的图片:在该文件夹下面直接建立nomedia的文件,任何途径都认为该文件夹是空的,所以读不出来,除非你进入文件管理器点击文件夹预览。
还有一办法就是下载第三方图片查看器让他自动生成上面所说的空文件信息。给你推荐【快图浏览】,通过隐藏文件夹功能达到目标。
㈥ android中怎么做自己的相册
package com.fit.background;
import Java.io.IOException;
import Android.app.Activity;
import android.app.WallpaperManager;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.NET.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
㈦ 安卓手机相册的问题
对于系统自带相册可以使用Gallery Excluder软件,使相册忽略扫描某些目录,该软件在Android 2.3下对应自带3D图库有效。
如果是用“快图浏览”一类的软件,这类软件本身就有隐藏和排除目录的功能,但是根据你的情况,你只需要在当前图库中不显示某一目录的话,用排除功能排除掉该目录就行了(隐藏功能会把文件放在系统隐藏目录,可能其他软件将无法识别,快图浏览本身也会给出说明)。
Gallery Excluder参考下载地址:http://as..com/a/item?docid=1988326&pre=web_am_se(其它应用市场也可找到)
㈧ android怎样调用系统相册
使用系统自带的图片浏览器应用程序Gallery可以打开一张指定的图片,//使用IntentIntent intent = new Intent(Intent.ACTION_VIEW);//Uri mUri = Uri.parse("file://" + picFile.getPath());Android3.0以后最好不要通过该方法,存在一些小Bugintent.setDataAndType(Uri.fromFile(picFile), "image/*");startActivity(intent)
㈨ android系统如何调用自带的相机相册
LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="gallery"
android:text="获取图库图片" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="camera"
android:text="拍照获取图片" />
<ImageView
android:id="@+id/iv_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
//------------------我的MainActivity --------------也很简单--------------------------
package tackpicture.bwie.com.tackpicture;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;
import java.io.File;
public class MainActivity extends AppCompatActivity {
private ImageView iv_image;
private static final int PHOTO_REQUEST_CAREMA = 1;// 拍照
private static final int PHOTO_REQUEST_GALLERY = 2;// 从相册中选择
private static final int PHOTO_REQUEST_CUT = 3;// 结果
/* 头像名称 */
private static final String PHOTO_FILE_NAME = "temp_photo.jpg";
private File tempFile;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//找到控件
iv_image = (ImageView) findViewById(R.id.iv_image);
}
//图库
public void camera(View view) {
// 激活系统图库,选择一张图片
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
// 开启一个带有返回值的Activity,请求码为PHOTO_REQUEST_GALLERY
startActivityForResult(intent, PHOTO_REQUEST_GALLERY);
}
//相机
public void gallery(View view) {
// 激活相机
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
// 判断存储卡是否可以用,可用进行存储
if (hasSdcard()) {
tempFile = new File(Environment.getExternalStorageDirectory(), PHOTO_FILE_NAME);
// 从文件中创建uri
Uri uri = Uri.fromFile(tempFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
}
// 开启一个带有返回值的Activity,请求码为PHOTO_REQUEST_CAREMA
startActivityForResult(intent, PHOTO_REQUEST_CAREMA);
}
/*
* 剪切图片
*/
private void crop(Uri uri) {
// 裁剪图片意图
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(uri, "image/*");
intent.putExtra("crop", "true");
// 裁剪框的比例,1:1
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
// 裁剪后输出图片的尺寸大小
intent.putExtra("outputX", 250);
intent.putExtra("outputY", 250);
intent.putExtra("outputFormat", "JPEG");// 图片格式
intent.putExtra("noFaceDetection", true);// 取消人脸识别
intent.putExtra("return-data", true);
// 开启一个带有返回值的Activity,请求码为PHOTO_REQUEST_CUT
startActivityForResult(intent, PHOTO_REQUEST_CUT);
}
/*
* 判断sdcard是否被挂载
*/
private boolean hasSdcard() {
if (Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
return true;
} else {
return false;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PHOTO_REQUEST_GALLERY) {
// 从相册返回的数据
if (data != null) {
// 得到图片的全路径
Uri uri = data.getData();
crop(uri);
}
} else if (requestCode == PHOTO_REQUEST_CAREMA) {
// 从相机返回的数据
if (hasSdcard()) {
crop(Uri.fromFile(tempFile));
} else {
Toast.makeText(MainActivity.this, "未找到存储卡,无法存储照片!", 0).show();
}
} else if (requestCode == PHOTO_REQUEST_CUT) {
// 从剪切图片返回的数据
if (data != null) {
Bitmap bitmap = data.getParcelableExtra("data");
this.iv_image.setImageBitmap(bitmap);
}
try {
// 将临时文件删除
tempFile.delete();
} catch (Exception e) {
e.printStackTrace();
}
}
super.onActivityResult(requestCode, resultCode, data);
}
}