?Gallery
Gallery完结的功用是将闪现的内容支配滑动。举例来说,有时我们下载一个APP运用的时分,会在运用商场中查看他的特性和界面,我们查看的内容通过支配滑动的方法来展示,这正本即是以Gallery控件来完结的。
Gallery的完结也需求运用Adapter。首先我们来看一下Gallery的几个常用特色:
- spacing特色:支配两个Item脱离多少距离;
- unselectAlpha特色:设置透明度;当在基地的Item获取到焦点时,将不会闪现闪现透明度的特色。
Gallery的监听通过onItemSelectListener 来完结,通过这个监听可以获取到在Gallery闪现过程中居中的View。
Activity内容:(Adapter的运用不再具体描绘)
public class MainActivity extends Activity { private Gallery mGalleryView; private ListmFruits; private LayoutInflater mInflater; private MyGalleryAdapter mMyGalleryAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mGalleryView = (Gallery) findViewById(R.id.galleray_fruit); mInflater = getLayoutInflater(); //数据初始化。 initData(); mMyGalleryAdapter = new MyGalleryAdapter(mFruits,mInflater); mGalleryView.setAdapter(mMyGalleryAdapter); //监听事情 mGalleryView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView adapterView, View view, int position, long l) { //将获取到焦点的生果,也即是居中的生果闪现出来。 Log.d("data", ""+mFruits.get(position).getmFruitName()); } @Override public void onNothingSelected(AdapterView adapterView) { } }); } private void initData() { mFruits =new ArrayList(); for (int i=0; i<10;i++){ Fruit apple = new Fruit(R.mipmap.apple,"苹果"); mFruits.add(apple); Fruit banana = new Fruit(R.mipmap.banana,"香蕉"); mFruits.add(banana); Fruit grape = new Fruit(R.mipmap.grape,"葡萄"); mFruits.add(grape); Fruit watermelon = new Fruit(R.mipmap.watermelon,"西瓜"); mFruits.add(watermelon); Fruit pineapple = new Fruit(R.mipmap.pineapple,"菠萝"); mFruits.add(pineapple); } 期待阅读具体教程网站www.keymob.com/tutorial_zh/index.html
时间: 2024-11-12 10:43:46