標籤:
?Gallery
Gallery完結的功用是將閃現的內容支配滑動。舉例來說,有時我們下載一個APP運用的時分,會在運用商場中查看他的特性和介面,我們查看的內容通過支配滑動的方法來展示,這正本即是以Gallery控制項來完結的。
Gallery的完結也需求運用Adapter。首先我們來看一下Gallery的幾個常用特色:
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
Android UI設計——Gallery控制項