Android 简单图片浏览器 ImageView
来源:互联网 发布:淘宝网儿童玩具手推车 编辑:程序博客网 时间:2024/05/01 19:37
main.xml文件:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical" android:background="#66FFCC" android:layout_width="fill_parent"android:layout_height="fill_parent"> <LinearLayout android:layout_width="fill_parent" android:layout_height="400dp" android:orientation="vertical" android:gravity="center_horizontal" > <!-- 定义显示图片整体的ImageView --><ImageView android:id="@+id/image1" android:layout_width="fill_parent" android:layout_height="match_parent" android:scaleType="fitCenter" android:src="@drawable/shuangta" /></LinearLayout> <LinearLayoutandroid:orientation="horizontal" android:layout_marginTop="3dp"android:layout_width="fill_parent"android:layout_height="wrap_content"android:gravity="center"><Button android:id="@+id/plus"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="增大透明度"/><Button android:id="@+id/minus"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="降低透明度"/><Button android:id="@+id/next"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="下一张"/></LinearLayout></LinearLayout>
MainActivity.java文件:
public class MainActivity extends Activity {//定义一个访问图片的数组int [] images = new int[]{R.drawable.lijiang,R.drawable.qiao,R.drawable.shuangta,R.drawable.shui,R.drawable.xiangbi,};//定义默认显示的图片int currentImg = 2;//定义图片的初始透明度private int alpha = 255; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); final Button plus = (Button) findViewById(R.id.plus); final Button minus = (Button) findViewById(R.id.minus); final Button next = (Button) findViewById(R.id.next); final ImageView image1 = (ImageView) findViewById(R.id.image1); //定义查看下一张图片的监听器 next.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View v) {// TODO Auto-generated method stubif(currentImg >= 4) currentImg = -1;BitmapDrawable bitmapDrawable = (BitmapDrawable) image1.getDrawable();//如果图片还未回收,先强制回收图片if(!bitmapDrawable.getBitmap().isRecycled()){bitmapDrawable.getBitmap().isRecycled();}image1.setImageBitmap(BitmapFactory.decodeResource(getResources(), images[++currentImg]));} }); OnClickListener listener = new OnClickListener(){@SuppressWarnings("deprecation")@Overridepublic void onClick(View v) {// TODO Auto-generated method stubif(v == plus) alpha += 50;if(v == minus) alpha -= 50;if(alpha >= 255) alpha = 255;if(alpha <= 0) alpha = 0;//改变图片的透明度image1.setAlpha(alpha);} }; plus.setOnClickListener(listener); minus.setOnClickListener(listener); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
效果图:
0 0
- Android 简单图片浏览器 ImageView
- 【Android】简单图片浏览器
- Android 简单图片浏览器
- ImageView:图片浏览器
- Android ImageView图片浏览器(ImageView加载sd卡图片资源)的内存溢出问题分析
- Android ImageView图片浏览器(ImageView加载sd卡图片资源)的内存溢出问题分析
- android开发简单图片浏览器
- android圆形图片显示ImageView超简单控件
- android ImageView图片缩放
- android ImageView图片缩放
- android Imageview 图片覆盖
- Android ImageView图片自适应
- Android ImageView图片自适应
- Android ImageView图片自适应
- Android ImageView图片自适应
- Android ImageView图片自适应
- Android ImageView图片自适应
- android ImageView制作图片
- 一个数组中某个键的值相同则把相同的数组组成一个新数组
- 从远程库克隆
- Github push 错误The requested URL returned error: 403 Forbidden while accessing
- alpha测试和beta测试的区别
- 数组的排序,反转,折半查找,插入
- Android 简单图片浏览器 ImageView
- Android模拟器:Genymotion
- 第8周—项目2 建立链串的算法库
- 第8周项目2-建立链串的算法库
- 在CentOS 7中安装与配置JDK8
- 三角形 算法第一集
- Bug的缺陷的优先级和严重程度
- C#命令模式
- JSP页面的基本结构