- 浏览: 20117 次
- 性别:
最新评论
imageView 做图片浏览器
==================================================================================
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/lowalpha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="降低透明度" />
<Button
android:id="@+id/upalpha"
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>
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="240px"
android:src="@drawable/lijiang"
android:scaleType="fitCenter" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="120dp"
android:layout_height="120dp"
android:background="#00f"
android:layout_marginTop="10dp"
/>
</LinearLayout>
===============================================================================
java代码:
package com.example.imageviewtest;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.util.Log;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends Activity {
private int alpha=255;
private Button plus;
private Button minus;
private Button next;
private ImageView image;
private ImageView image2;
int currentImg=2;
//private BitmapDrawable bitmapdrawable;
//int [] images=new int[]{R.drawable.landscape,R.drawable.landscape1,R.drawable.landscape2,R.drawable.landscape3,R.drawable.landscape4,R.drawable.landscape5};
int [] images=new int[]{R.drawable.lijiang,R.drawable.qiao,R.drawable.shuangta,R.drawable.shui,R.drawable.xiangbi};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
plus=(Button)findViewById(R.id.upalpha);
minus=(Button)findViewById(R.id.lowalpha);
image=(ImageView)findViewById(R.id.imageView1);
next=(Button)findViewById(R.id.next);
image2=(ImageView)findViewById(R.id.imageView2);
OnClickListener listener=new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(arg0==plus)
{
alpha+=20;
}
if(arg0==minus)
{
alpha-=20;
}
if(alpha>=255)
{
alpha=255;
}
if(alpha<0)
{
alpha=0;
}
image.setAlpha(alpha);
}
};
plus.setOnClickListener(listener);
minus.setOnClickListener(listener);
next.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
image.setImageResource(images[++currentImg%images.length]);
}
});
image.setOnTouchListener( new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.i("Image","Test");
// TODO Auto-generated method stub
BitmapDrawable bitmapdrawable=(BitmapDrawable)image.getDrawable();
Bitmap bitmap=bitmapdrawable.getBitmap();
double scale=bitmap.getWidth()/320.0;
int x=(int) (event.getX()*scale);
int y=(int) (event.getY()*scale);
Log.i("Image","width"+bitmap.getWidth()+"height"+bitmap.getHeight());
Log.i("Image","x:"+x+"y:"+y);
if(x+120>bitmap.getWidth())
{
x=bitmap.getWidth()-120;
}
if(y+120>bitmap.getHeight())
{
y=bitmap.getHeight()-120;
}
Log.i("Image",""+x+" "+y);
image2.setImageBitmap(Bitmap.createBitmap(bitmap,x,y,120,120));
//alpha=0;
image2.setAlpha(alpha); // alpha 如果很小,会可能无法显示图片,原因是 图片透明了,所以无法看到图片。切记,。。
return false;
}
} );
}
@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;
}
}
==================================================================================
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/lowalpha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="降低透明度" />
<Button
android:id="@+id/upalpha"
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>
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="240px"
android:src="@drawable/lijiang"
android:scaleType="fitCenter" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="120dp"
android:layout_height="120dp"
android:background="#00f"
android:layout_marginTop="10dp"
/>
</LinearLayout>
===============================================================================
java代码:
package com.example.imageviewtest;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.util.Log;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends Activity {
private int alpha=255;
private Button plus;
private Button minus;
private Button next;
private ImageView image;
private ImageView image2;
int currentImg=2;
//private BitmapDrawable bitmapdrawable;
//int [] images=new int[]{R.drawable.landscape,R.drawable.landscape1,R.drawable.landscape2,R.drawable.landscape3,R.drawable.landscape4,R.drawable.landscape5};
int [] images=new int[]{R.drawable.lijiang,R.drawable.qiao,R.drawable.shuangta,R.drawable.shui,R.drawable.xiangbi};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
plus=(Button)findViewById(R.id.upalpha);
minus=(Button)findViewById(R.id.lowalpha);
image=(ImageView)findViewById(R.id.imageView1);
next=(Button)findViewById(R.id.next);
image2=(ImageView)findViewById(R.id.imageView2);
OnClickListener listener=new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(arg0==plus)
{
alpha+=20;
}
if(arg0==minus)
{
alpha-=20;
}
if(alpha>=255)
{
alpha=255;
}
if(alpha<0)
{
alpha=0;
}
image.setAlpha(alpha);
}
};
plus.setOnClickListener(listener);
minus.setOnClickListener(listener);
next.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
image.setImageResource(images[++currentImg%images.length]);
}
});
image.setOnTouchListener( new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.i("Image","Test");
// TODO Auto-generated method stub
BitmapDrawable bitmapdrawable=(BitmapDrawable)image.getDrawable();
Bitmap bitmap=bitmapdrawable.getBitmap();
double scale=bitmap.getWidth()/320.0;
int x=(int) (event.getX()*scale);
int y=(int) (event.getY()*scale);
Log.i("Image","width"+bitmap.getWidth()+"height"+bitmap.getHeight());
Log.i("Image","x:"+x+"y:"+y);
if(x+120>bitmap.getWidth())
{
x=bitmap.getWidth()-120;
}
if(y+120>bitmap.getHeight())
{
y=bitmap.getHeight()-120;
}
Log.i("Image",""+x+" "+y);
image2.setImageBitmap(Bitmap.createBitmap(bitmap,x,y,120,120));
//alpha=0;
image2.setAlpha(alpha); // alpha 如果很小,会可能无法显示图片,原因是 图片透明了,所以无法看到图片。切记,。。
return false;
}
} );
}
@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;
}
}
发表评论
-
ArrayAdapter requires the resource ID to be a TextView问题
2013-08-09 07:00 1059在使用ArrayAdapter时使用自己写的R.layout. ... -
疯狂android讲义学习总结---toggle与switch
2013-05-16 18:49 1547ToggleButton 与Switch二者都是Button的 ... -
疯狂android讲义学习总结---RadioButton——CheckBox
2013-05-16 12:10 784RadioButton(单选按钮)与CheckBox(复选框) ... -
疯狂android讲义学习总结---TextView
2013-05-16 10:50 744这里只想说一句,在EditText中 如果想让输入框中的有默认 ... -
疯狂android讲义学习总结---各种按钮的制作
2013-05-16 10:46 695第一种:给按钮的文字加重影操作 <Button ... -
android之sqlite数据库初级
2013-03-11 23:52 541package com.example.testsqlite; ... -
libgdx--中文显示与汉字绘制
2013-03-05 11:02 1244要用libgdx框架下显示中文 那么不得不用到hiero工具首 ... -
libgdx的使用--绘制图片
2013-03-02 14:19 856上一节我们用到了SpriteBatch类 但是我们并没有使用它 ... -
libgdx的使用--环境搭建测试
2013-03-02 11:00 646首先在eclise中创建android工程 new--> ...
相关推荐
Android studio开发可能需要的jar包。
android-shape-imageview - 图片圆角、三角、五角、圆形、多角
安卓Android源码——gesture-imageview.zip
19Android-11-imageView.mp4
2.3.7 图像视图(ImageView)的 功能和用法 75 2.4 高级界面组件 79 2.4.1 自动完成文本框(AutoCompleteTextView)的 功能和用法 79 2.4.2 Spinner的功能和用法 80 2.4.3 日期、时间选择器...
ImageView with a tag in android. So it's a ImageView. Demo Warning:When you set the round radius,the simpletagimageview scale type just support fitXY now! Usage Quick Start Gradle compile '...
Android高级应用源码-ImageView 自定义控件,实现圆角控件图片功能.zip
《疯狂Android讲义(第2版)》.(李刚).源代码 疯狂Android讲义目录结构: 第2章、Android应用程序界面设计,即View 2.2、布局管理(Layout):LinearLayout、TableLayout、FrameLayout、RelativeLayout; 2.3、基本...
progress-image-view-android 带简单进度的android ImageView控件
android-shape-imageview自定义形状的 imageview.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
on android ImageView when it's being vertically or horizontally scrolled (moving) on the screen. I wrote an article explaining how this works and implemented, please check it out ...
android gesture-imageview源码.zip
ElevationImageView - 带高程阴影的Imageview
RCImageView 自定义圆角ImageView,带边框效果
Android ImageView自定义实现,支持缩放,由不同的触控手势
Android高级应用源码-ImageViewEx 支持Gif显示的ImageView.zip
The idea of this android library is to give the possibility to display two texts inside the imageitself. These texts could be the title or the description of the image or something else. Also there ...
用于android的Imageview缩放库