android 在Gallery下面加入导航条视图,当拖动Gallery时,导航条根据当前图片在Gallery中的位置而显示进度
1个回答
展开全部
Gallery是一个类似于ListView的视图可以实现左右缓慢拖动屏幕切换图片的功能
package com.test;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.text.Layout;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
public class SpinnerActivity extends Activity {
private Gallery gallery;
private List<Bitmap> list = new ArrayList<Bitmap>();;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
gallery = (Gallery) findViewById(R.id.images);
init();
gallery.setAdapter(new MyAdapter());
}
private void init() {
// 通过图片工厂得到图片对象,并加入到集合中
list.add(BitmapFactory.decodeResource(getResources(), R.drawable.icon));
list.add(BitmapFactory.decodeResource(getResources(), R.drawable.icon));
list.add(BitmapFactory.decodeResource(getResources(), R.drawable.icon));
list.add(BitmapFactory.decodeResource(getResources(), R.drawable.icon));
list.add(BitmapFactory.decodeResource(getResources(), R.drawable.icon));
}
class MyAdapter extends BaseAdapter
package com.test;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.text.Layout;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
public class SpinnerActivity extends Activity {
private Gallery gallery;
private List<Bitmap> list = new ArrayList<Bitmap>();;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
gallery = (Gallery) findViewById(R.id.images);
init();
gallery.setAdapter(new MyAdapter());
}
private void init() {
// 通过图片工厂得到图片对象,并加入到集合中
list.add(BitmapFactory.decodeResource(getResources(), R.drawable.icon));
list.add(BitmapFactory.decodeResource(getResources(), R.drawable.icon));
list.add(BitmapFactory.decodeResource(getResources(), R.drawable.icon));
list.add(BitmapFactory.decodeResource(getResources(), R.drawable.icon));
list.add(BitmapFactory.decodeResource(getResources(), R.drawable.icon));
}
class MyAdapter extends BaseAdapter
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询