android 入门 Gallery
16lz
2021-12-04
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>
更多相关文章
- Android(安卓)BottomNavigationView的使用
- android收发短信
- android UI组件
- android clipPath切割画布
- Android(安卓)WiFi管理(WIFI_SERVICE)
- Android搜索框自动提示文本框——(单一提示)
- Android(安卓)自定义SeekBar显示进度百分比
- android中sqlite的使用
- Android在屏幕任意位置显示对话框