設置未選中的條目的透明度(Alpha)。該值必須是float類型,比如:“1.2”。
</td>
</tr>
</tbody>
</table>
<3>范例

package xiaosi.gallery;
import android.app.Activity;
import android.content.Context;
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.widget.Toast;
public class GalleryActivity extends Activity {
/* Called when the activity is first created. /
private Gallery gallery =null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
gallery = (Gallery)findViewById(R.id.gallery);
//設置圖片適配器
gallery.setAdapter(new ImageAdapter(this));
gallery.setSpacing(10);
//設置監聽器
gallery.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Toast.makeText(GalleryActivity.this, "點擊了第"+arg2+"張圖片", Toast.LENGTH_LONG).show();
}
});
}
}
class ImageAdapter extends BaseAdapter{
private Context context;
//圖片源數組
private Integer[] imageInteger={
R.drawable.a,
R.drawable.b,
R.drawable.c,
R.drawable.d,
R.drawable.e,
R.drawable.f,
};
public ImageAdapter(Context c){
context = c;
}
// 獲取圖片的個數
public int getCount() {
return imageInteger.length;
}
// 獲取圖片在庫中的位置
public Object getItem(int position) {
return position;
}
// 獲取圖片ID
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(context);
// 給ImageView設置資源
imageView.setImageResource(imageInteger[position]);
// 設置顯示比例類型
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
// 設置布局 圖片120*80
imageView.setLayoutParams(new Gallery.LayoutParams(120, 80));
return imageView;
}
}</pre>
main.xml<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="
<Gallery
android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:background="?android:galleryItemBackground"/>
</LinearLayout></pre>
轉自:http://blog.csdn.net/sjf0115/article/details/7253332
本文由用戶 openkk 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!
|