android 入门 Gallery
16lz
2021-01-23
package com.zte.android.lesstion; import android.app.Activity;import android.os.Bundle;import android.view.View;import android.widget.AdapterView.OnItemSelectedListener;import android.widget.AdapterView;import android.widget.Gallery;import android.widget.Toast;/** * @author rychenga * * 水平方向上显示一组图片,以便于浏览 */public class Activity_012_Gallery extends Activity{private Gallery gallery ;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.activity_012_gallery_layout);//init gallerygallery = (Gallery)findViewById(R.id.l012_gallery1);//设置适配器(datasource)Activity_012_ImageAdapter adapter = new Activity_012_ImageAdapter(Activity_012_Gallery.this);gallery.setAdapter(adapter);//显示被选中部分所处的位置,显示信息持续2秒gallery.setOnItemSelectedListener(new OnItemSelectedListener() {//覆盖2个默认方法public void onItemSelected(AdapterView<?> parent, View view,int position, long id) {// TODO Auto-generated method stubToast.makeText(Activity_012_Gallery.this,"第"+position+"张", 2).show();}public void onNothingSelected(AdapterView<?> arg0) {// TODO Auto-generated method stub}});}}
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Gallery android:id="@+id/l012_gallery1" android:layout_width="match_parent" android:layout_height="300dp"/></LinearLayout>
更多相关文章
- 几种常用的适配器--Adapter
- Android中自定义水平的ProgressBar
- [置顶] Android常用适配器控件
- Android踩坑日记:自定义水平和圆形ProgressBar样式
- Android UI设计——ListView控件与SimpleAdapter适配器(三)
- 使用android中drawline函数无法绘制水平线的解决办法
- Android studio :适配器控件
- Android适配器之-----SimpleCursorTreeAdapter
- Android的水平进度条和圆形进度条实例