當前位置:首頁 » 安卓系統 » android的gallery

android的gallery

發布時間: 2022-12-28 22:55:51

A. 如何打開圖庫android gallery

Android原生內置了很多App,而Gallery為圖庫,用於操作設備上的圖片,它會在開機的時候主動掃描設備上存儲的圖片,並可以使用Gallery操作它們。既然要使用Gallery,那麼先看看它的AndroidManifest.xml清單文件。

<activity android:name="com.android.camera.ImageGallery"
android:label="@string/gallery_label"
android:configChanges="orientation|keyboardHidden"
android:icon="@drawable/ic_launcher_gallery">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.dir/image" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.dir/video" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.OPENABLE" />
<data android:mimeType="vnd.android.cursor.dir/image" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.OPENABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="video/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="video/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.dir/image" />
</intent-filter>
</activity>
上面是Gallery的AndroidManifest.xml文件中的部分代碼,展示了ImageGallery,從眾多Intent-filter中可以看出,選取圖片應該使用"android.intent.action.PICK",它有兩個miniType,"image/*"是用來獲取圖片的、"video/*"是用來獲取視頻的。Android中眾多Action的字元串其實被封裝在Intent類中,android.intent.action.PICK也不例外,它是Intent.ACTION_PICK。

既然知道了啟動Gallery的Action,那麼再看看ImageGallery.java源碼,找找其中選中圖片後的返回值。

private void launchCropperOrFinish(IImage img) {
Bundle myExtras = getIntent().getExtras();

long size = MenuHelper.getImageFileSize(img);
if (size < 0) {
// Return if the image file is not available.
return;
}

if (size > mVideoSizeLimit) {
DialogInterface.OnClickListener buttonListener =
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
};
new AlertDialog.Builder(this)
.setIcon(android.R.drawable.ic_dialog_info)
.setTitle(R.string.file_info_title)
.setMessage(R.string.video_exceed_mms_limit)
.setNeutralButton(R.string.details_ok, buttonListener)
.show();
return;
}

String cropValue = myExtras != null ? myExtras.getString("crop") : null;
if (cropValue != null) {
Bundle newExtras = new Bundle();
if (cropValue.equals("circle")) {
newExtras.putString("circleCrop", "true");
}

Intent cropIntent = new Intent();
cropIntent.setData(img.fullSizeImageUri());
cropIntent.setClass(this, CropImage.class);
cropIntent.putExtras(newExtras);

/* pass through any extras that were passed in */
cropIntent.putExtras(myExtras);
startActivityForResult(cropIntent, CROP_MSG);
} else {
Intent result = new Intent(null, img.fullSizeImageUri());
if (myExtras != null && myExtras.getBoolean("return-data")) {
// The size of a transaction should be below 100K.
Bitmap bitmap = img.fullSizeBitmap(
IImage.UNCONSTRAINED, 100 * 1024);
if (bitmap != null) {
result.putExtra("data", bitmap);
}
}
setResult(RESULT_OK, result);
finish();
}
}
以上的ImageGallery.java的部分源碼,從setResult()方法可以看出,它返回的Intent包含了選中圖片的Uri,它是一個content://開頭的內容提供者,並且如果傳遞過去的Intent的Extra中,包含一個name為"return-data"並且值為true的時候,還會往Extra中寫入name為"data"的圖片縮略圖。

B. 關於android 的gallery 控制項的問題

第一個問題你可以gallery.setSelection(index)解決,index自己調試,一般為1或者2就OK了,如果還沒到最左邊,在適當增加index的值。
第二個問題你可以在adapter類中先定義個list對象,然後再activity中對list設值,當要修改時,只需要修改傳入list的值,然後再notifydatachange()就OK了。

C. android Gallery怎麼縱向顯示

用動畫旋轉90度就可以縱向顯示了,以下函數,RotateAnimation是android提供的類Gallery.startAnimaiton(RotateAnimation a)

D. 怎樣向android的Gallery里動態添加圖片

Gallery使用大致方法為
1
定義綁定
mGallery
=
(Gallery)findView...
2
定義適配器
MyAdapter
mAdapter
=
new
MyAdapter(.....,list);
注意list
3
為Gallery設置適配器
mGallery.setAdapter(mAdapter);
然後回到問題如何動態添加圖片,
list是你的數據源,新加的圖片資源應該加到list中,然後刷新Adapter就行了,比如點擊某按鈕添加某張圖片
button.setOnClickListener(new
OnClickListener()
{
@Override
public
void
onClick(View
v)
{
1.添加圖片,本地或者網路圖片根據你的需要
list.add("picture");
2.刷新適配器
mAdapter.notifyDataSetChanged();
}
});

E. android 如何讓gallery自動滾動

讓gallery自動滾動可以通過以下兩種方法實現:

一、使用Timer和TimerTask類來完成圖片的自動定時滾動:

思路:循環調用Gallery類的onFling()方法。

代碼:

<span style="white-space:pre"> </span>task = new TimerTask() {

@Override
public void run() {
/**
* 參數1和2:手指在gallery上的動作
* 參數3和4:x方向和y方向的滾動的速度,-數表示向左滾,+數表示向右
*/
gallery.onFling(null, null, -750, 0);
}
};
timer.schele(task, 1000, 5000);
<span style="font-size:32px;"><strong>
</strong></span>
<span style="font-size:32px;"><strong>方式2:</strong></span>

二、使用Handler消息機制完成

思路:子線程內死循環使用handler每隔多長時間向主線程發送消息,通知gallery改變位置。

代碼:

子線程部分:
<span style="white-space:pre"> new Thread(new Runnable() {
<span style="white-space:pre"> </span>int flag = 1;
<span style="white-space:pre"> </span>@Override
<span style="white-space:pre"> </span>public void run() {
<span style="white-space:pre"> </span>while (isalive) {
<span style="white-space:pre"> </span>//images為裝圖片的集合
<span style="white-space:pre"> </span>if ((cur_index + 1) == images.size()) {
<span style="white-space:pre"> </span>flag = -1;
<span style="white-space:pre"> </span>} else if (cur_index == 0) {
<span style="white-space:pre"> </span>flag = 1;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>Message msg = handler.obtainMessage(MSG_UPDATE, cur_index,
<span style="white-space:pre"> </span>0);
<span style="white-space:pre"> </span>handler.sendMessage(msg);
<span style="white-space:pre"> </span>try {
<span style="white-space:pre"> </span>Thread.sleep(4000);
<span style="white-space:pre"> </span>} catch (InterruptedException e) {
<span style="white-space:pre"> </span>e.printStackTrace();
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>switch (flag) {
<span style="white-space:pre"> </span>case 1:
<span style="white-space:pre"> </span>cur_index++;
<span style="white-space:pre"> </span>break;
<span style="white-space:pre"> </span>case -1:
<span style="white-space:pre"> </span>cur_index--;
<span style="white-space:pre"> </span>break;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>}).start();</span>
主線程部分:
private Handler handler = new Handler() {
public void handleMessage(Message msg) {
if (msg.what == MSG_UPDATE) {
gallery.setSelection(msg.arg1);
}
}
};

兩種方式的優缺點:

優點:

使用方式1來實現,效果和手指拖動的效果一樣,滾動速度可以自己調。

使用方式2來實現,可以使用繼承Gallery的子類,重寫onFling方法,返回false來實現手指拖動時圖片只滾動一張的效果。

缺點:

使用方式1來實現,當你用手指拖動,就會發現圖片滾動的太快了,不是一張一張的滾動的,沒法使用繼承Gallery的子類,重寫onFling方法,返回false來實現手

使用方式2來實現 ,效果沒那麼好看,圖片說換就換了,沒緩沖,滾動速度沒法控制。

F. android中的gallery過時了,現在用什麼來替代它

HorizontalScrollView 或者ViewPager。

G. android gallery要怎麼初始化

啟動代碼里初始化Gallery,這里主要用到Gallery控制項的 setImageResource()[顯示內容] 和 setLayoutParams()[顯示屬性] 方法。最最關鍵的是定製適配器 ImageShowAdapter。而實現循環是通過對position求余實現,Gallery開始時會調用getCount()函數,確定有多少個View要繪制,當繪制到最後一個以後就結束了。為了實現循環我們設置getCount()的返回值為Integer的最大值,這樣Gallery就可以繪制足夠多的View,但是我們設定的資源圖片數組大小為4,要想循環當然要用到取模運算啦。
package com.adamhu.dianxiaoer;

import java.lang.reflect.Field;
import java.util.ArrayList;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class EntryActivity extends Activity {

private Gallery mGallery;
private ImageView mImgView;
private ImageShowAdapter mAdapter = new ImageShowAdapter(this);

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_entry);

mGallery = (Gallery) findViewById(R.id.gallery);
mImgView = (ImageView) findViewById(R.id.image_view);
try {
mGallery.setAdapter(mAdapter);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mGallery.setOnItemClickListener(new AdapterView.OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View v, int position, long id){
Integer[] iView = mAdapter.getImagesId();
mImgView.setImageDrawable(getResources().getDrawable(iView[position%iView.length]));
}
});

}

public class ImageShowAdapter extends BaseAdapter{

private Context mContext;
private ArrayList<Integer> imgList = new ArrayList<Integer>();
private ArrayList<Object> imgSize = new ArrayList<Object>();

public ImageShowAdapter(Context c){
mContext = c;

}

@Override
public int getCount() {
// TODO Auto-generated method stub
return Integer.MAX_VALUE;
}

@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}

@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ImageView i = new ImageView(mContext);
i.setImageResource(mImagesId[position%mImagesId.length]);
i.setLayoutParams(new Gallery.LayoutParams(270,190));
return i;
}

public Integer[] getImagesId(){
return mImagesId;
}

public void setImagesId(Integer[] mImagesId){
this.mImagesId = mImagesId;
}

private Integer mImagesId[] = {
R.drawable.image1,
R.drawable.image10,
R.drawable.image11,
R.drawable.image12
};

}

}

H. 在android系統 里的 gallery什麼意思啊

android系統里的「gallery」指的是圖庫相冊。

gallery 表示:n. 畫廊;走廊;旁聽席;地道;vt. 在?修建走廊;在?挖地道;vi. 挖地道

相關短語

1、art gallery美術館;畫廊

2、photo gallery圖片庫

3、picture gallery畫館;美術館

(8)android的gallery擴展閱讀:

近義詞:n. 畫廊;走廊;旁聽席;地道 hall、passage、corridor、underground、subway

gallery 來自拉丁語Galilaea, 現巴勒斯坦地名Galilee,原指位於Galilee的教堂門廊,走廊。

雙語例句

1、Beforewego tothegallery.

在我們去畫廊之前。

2、Isthisyourgallery?

這是你的畫廊嗎?

3、Sowhat diddadhave todo at thegallery.

那麼其實爸爸要去畫廊做什麼?

熱點內容
scratch少兒編程課程 發布:2025-04-16 17:11:44 瀏覽:625
榮耀x10從哪裡設置密碼 發布:2025-04-16 17:11:43 瀏覽:355
java從入門到精通視頻 發布:2025-04-16 17:11:43 瀏覽:70
php微信介面教程 發布:2025-04-16 17:07:30 瀏覽:295
android實現陰影 發布:2025-04-16 16:50:08 瀏覽:786
粉筆直播課緩存 發布:2025-04-16 16:31:21 瀏覽:336
機頂盒都有什麼配置 發布:2025-04-16 16:24:37 瀏覽:201
編寫手游反編譯都需要學習什麼 發布:2025-04-16 16:19:36 瀏覽:797
proteus編譯文件位置 發布:2025-04-16 16:18:44 瀏覽:354
土壓縮的本質 發布:2025-04-16 16:13:21 瀏覽:581