GridView + ImageSwitch 图片点击切换
2012-11-16 12:36
218 查看
效果:
点击上面的图片,下面的大图实现切换
此包含三个文件: 两个xml一个主程序java文件
java代码:
[/code]
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
主布局文件:
[/code]
另一个xml文件 cell.xml
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
点击上面的图片,下面的大图实现切换
此包含三个文件: 两个xml一个主程序java文件
java代码:
public class MainActivity extends Activity {
[code]
private static final String tag = "==CrazyIt.org==";
int[] imgs = new int[] { R.drawable.x1, R.drawable.x2, R.drawable.x3,
R.drawable.x5, R.drawable.x4 };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
List<Map<String, Object>> li = new ArrayList<Map<String, Object>>();
for (int i = 0; i < imgs.length; i++) {
Map<String, Object> l = new HashMap<String, Object>();
l.put("image", imgs[i]);
li.add(l);
}
final ImageSwitcher is = (ImageSwitcher) findViewById(R.id.is1);
is.setInAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.slide_in_left));
is.setOutAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.slide_out_right));
is.setFactory(new ViewFactory() {
public View makeView() {
// TODO Auto-generated method stub
ImageView iv = new ImageView(MainActivity.this);
iv.setBackgroundColor(0xff0000);
iv.setScaleType(ImageView.ScaleType.FIT_CENTER);
iv.setLayoutParams(new ImageSwitcher.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
return iv;
}
});
SimpleAdapter sa = new SimpleAdapter(this, li, R.layout.cell,
new String[] { "image" }, new int[] { R.id.image1 });
GridView gv = (GridView) findViewById(R.id.gv1);
gv.setAdapter(sa);
gv.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int position, long arg3) {
// TODO Auto-generated method stub
is.setImageResource(imgs[position % imgs.length]);
Toast.makeText(MainActivity.this,
String.valueOf(position % imgs.length),
Toast.LENGTH_LONG).show();
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
gv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
// TODO Auto-generated method stub
is.setImageResource(imgs[position % imgs.length]);
Toast.makeText(MainActivity.this,
String.valueOf(position % imgs.length),
Toast.LENGTH_LONG).show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
[/code]
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
主布局文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
[code] xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<GridView
android:id="@+id/gv1"
android:layout_width="match_parent"
android:layout_height="139dp"
android:numColumns="8" >
</GridView>
<ImageSwitcher
android:id="@+id/is1"
android:layout_width="match_parent"
android:layout_height="184dp"
android:layout_gravity="center_horizontal"
android:layout_weight="4.06"
android:padding="40dp" >
</ImageSwitcher>
</LinearLayout>
[/code]
另一个xml文件 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" android:baselineAligned="true" android:gravity="center_horizontal" android:orientation="vertical" > <ImageView android:id="@+id/image1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
相关文章推荐
- 自定义ImageView点击实现两张图片切换
- GridView+pagerViewer 图片浏览,点击全屏,滑动左右切换+删除关闭+拍照
- 新手学习之点击gridview切换图片,以及图片的显示和隐藏
- 在imageView依次添加7个手势, 1.点击哪个按钮,往imageView上添加哪个手势.(保证视图上只有一个手势). 2.轻拍:点击视图切换美女图片.(imageView上首先展示的美女
- 类型为image的input标签,鼠标点击切换按钮背景图片
- 在imageView依次加入7个手势, 1.点击哪个button,往imageView上加入哪个手势.(保证视图上仅仅有一个手势). 2.轻拍:点击视图切换美女图片.(imageView上首先展示的美女
- Android ImageSwitcher 图片切换 按钮点击切换
- Android自定义ImageView实现点击两张图片切换效果
- 如何实现点击GridView中一个图片后,如何传递至一个新的Activity中的imageview里面显示?
- GridView+ImageSwitcher实现的图片切换(左滑右滑切换)
- Android gridview 点击item切换图片
- 自定义ImageView点击实现两张图片切换
- Android中点击button,实现ImageView中图片的循环切换
- 自定义ImageView点击实现两张图片切换
- tab栏切换(点击图片切换路径)
- Android中使用imageviewswitcher 实现图片切换轮播导航的方法
- 使用AsyncTask完成点击按钮下载图片到ImageView控件上
- 实现点击图片下标切换图片
- Android让ImageView点击后换成另外一张图片
- Android中使用ImageViewSwitcher实现图片切换轮播导航效果