Gallery 的 Demo
来源:未知 责任编辑:责任编辑 发表时间:2013-12-18 11:34 点击:次
Gallery 的 Demo
gallery.xml
代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!--
Gallery - 缩略图浏览器控件
spacing - 缩略图列表中各个缩略图之间的间距
-->
<Gallery android:id="@+id/gallery" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:spacing="20px" />
</LinearLayout>
_Gallery.java
代码
package com.webabcd.view;
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.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.Gallery.LayoutParams;
public class _Gallery extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setContentView(R.layout.gallery);
setTitle("Gallery");
Gallery gallery = (Gallery) findViewById(R.id.gallery);
// 为缩略图浏览器指定一个适配器
gallery.setAdapter(new ImageAdapter(this));
// 响应 在缩略图列表上选中某个缩略图后的 事件
gallery.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View v,
int position, long id) {
gallery.xml
代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!--
Gallery - 缩略图浏览器控件
spacing - 缩略图列表中各个缩略图之间的间距
-->
<Gallery android:id="@+id/gallery" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:spacing="20px" />
</LinearLayout>
_Gallery.java
代码
package com.webabcd.view;
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.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.Gallery.LayoutParams;
public class _Gallery extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setContentView(R.layout.gallery);
setTitle("Gallery");
Gallery gallery = (Gallery) findViewById(R.id.gallery);
// 为缩略图浏览器指定一个适配器
gallery.setAdapter(new ImageAdapter(this));
// 响应 在缩略图列表上选中某个缩略图后的 事件
gallery.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View v,
int position, long id) {
相关新闻>>
- 发表评论
-
- 最新评论 更多>>