Android GridView ImageSwitcher
来源:互联网 发布:java iterator 实现类 编辑:程序博客网 时间:2024/06/05 18:04
GridView
android:columnWidth setColumnWidth(int)设置列的宽度
android:gravity setGravity(int)设置对齐方式
android:horizontalSpacing setHorizontalSpacing(int)设置各元素之间的水平间距
android:numColumns setNumColumns(int)设置列数
android:stretchMode setStretchMode(int)设置拉伸模式
android:verticalSpacing setVerticalSpacing(int)设置各元素之间的垂直间距
andorid:stretchMode属性值:
NO_STRETCH:不拉伸
STRETCH_SPACING:仅拉伸元素之间的间距
STRETCH_SPACING_UNIFORM:表格元素本身,元素之间的间距一起拉伸
STRETCH_COLUMN_WIDTH:仅拉伸表格元素本身
package shortcut.song.com.myapplication;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.view.animation.AnimationUtils;import android.widget.AdapterView;import android.widget.FrameLayout;import android.widget.GridView;import android.widget.ImageSwitcher;import android.widget.ImageView;import android.widget.SimpleAdapter;import android.widget.ViewSwitcher;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;public class GridViewActivity extends AppCompatActivity { GridView mGridView; ImageSwitcher mImageSwitcher; private int images[] = { R.drawable.play,R.drawable.alert_dialog_icon, R.drawable.img1, R.drawable.img2, R.drawable.img3, R.drawable.sun, R.drawable.play, R.drawable.img1, R.drawable.sun, }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_grid_view); mGridView = (GridView)findViewById(R.id.gridview1); mImageSwitcher = (ImageSwitcher)findViewById(R.id.imagesswitcher1); mImageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in)); mImageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out)); mImageSwitcher.setFactory(new ViewSwitcher.ViewFactory() { @Override public View makeView() { ImageView imageView = new ImageView(GridViewActivity.this); imageView.setBackgroundColor(0xff000000); imageView.setScaleType(ImageView.ScaleType.FIT_CENTER); imageView.setLayoutParams(new ImageSwitcher.LayoutParams(ImageSwitcher.LayoutParams.WRAP_CONTENT, ImageSwitcher.LayoutParams.WRAP_CONTENT)); return imageView; } }); List<Map<String, Object>> mLists = new ArrayList<Map<String, Object>>(); for (int i=0; i < images.length; i++ ) { Map<String, Object> mList = new HashMap<String, Object>(); mList.put("image", images[i]); mLists.add(mList); } SimpleAdapter simpleAdapter = new SimpleAdapter(this, mLists, R.layout.cell, new String[] {"image"}, new int[] {R.id.cell_img}); mGridView.setAdapter(simpleAdapter); mGridView.setChoiceMode(GridView.CHOICE_MODE_SINGLE); mGridView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { mImageSwitcher.setImageResource(images[position % images.length]); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mImageSwitcher.setImageResource(images[ position % images.length]); } }); }}
//cell.xml
<?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"> <ImageView android:id="@+id/cell_img" android:layout_width="50dp" android:layout_height="50dp" /></LinearLayout>
//mxl 布局文件
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_grid_view" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="shortcut.song.com.myapplication.GridViewActivity"> <GridView android:id="@+id/gridview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:numColumns="3" android:choiceMode="singleChoice" android:horizontalSpacing="5dp" android:verticalSpacing="5dp" android:gravity="center" /> <ImageSwitcher android:id="@+id/imagesswitcher1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" /></RelativeLayout>
0 0
- Android GridView ImageSwitcher
- Android:Gallery,ImageSwitcher 和GridView用法
- Android ImageSwitcher
- Android ImageSwitcher
- android ImageSwitcher
- android ImageSwitcher
- 系出名门Android(8) - 控件(View)之TextSwitcher, Gallery, ImageSwitcher, GridView, ListView, ExpandableList
- 系出名门Android(8) - 控件(View)之TextSwitcher, Gallery, ImageSwitcher, GridView, ListView, ExpandableList
- 系出名门Android(8) - 控件(View)之TextSwitcher, Gallery, ImageSwitcher, GridView, ListVi
- Android高级控件(View)之四TextSwitcher, Gallery, ImageSwitcher, GridView, ListView, ExpandableList
- android学习之--网格视图(GridView)和图像切换器(ImageSwitcher)
- Android之ImageSwitcher
- android控件18 ImageSwitcher
- android 之 ImageSwitcher学习
- 【Android 开发教程】ImageSwitcher
- Android入门/ImageSwitcher(十四)
- Android的ImageSwitcher效果
- Android之ImageSwitcher
- [luogu P2526][SHOI2001]小狗散步(二分图最大匹配)
- JS中typeof与instanceof的区别
- Log4j详解
- 使用MyEclipse自带的jar搭建SSH框架
- php中json_decode返回值为NULL的解决方法
- Android GridView ImageSwitcher
- ACM 深搜&广搜 Counting Sheep&Space Exploration
- Matlab编程与数据类型 -- 字符型数组
- java中GMT时间格式转换(其中一种方法)
- 1.(初级)伪类及伪元素
- UUID做主键,好还是不好?这是个问题。
- Windows编程入门-字符编码
- 无限防 助你一臂之力 !!
- 文件