<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText android:paddingRight="0dp"
android:layout_width="wrap_content"
android:layout_height="fill_parent"/>
<Button android:paddingLeft="0dp"
android:layout_width="wrap_content"
android:layout_height="fill_parent"/>
</LinearLayout>
http://www.geting.se/viewimage/image/249016-Untitled-3.jpg
关键是android:paddingRight="0dp"
要做的逼真点,那个圆角最好使用.9png
初学android,学着做了一个小例子,例子非常简单,就是用Gallery实现一个简单的相册,由于我是初学者,所以我遇到的问题可能也是初学者也会遇到的问题,在完成这个小例子过程中遇到了很多意想不到的问题,最后借助网络都解决了,现在把我做的这个小例子拿出分享给各位初学者!我做了尽可能详细的注释,我想一定会对初学者有所帮助!由于初学android,例子也是超级简单,路过的各位大侠请勿见笑!
Gallery:即图片浏览控件
layout部分:
<?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" >
<Gallery android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
</Gallery>
<ImageView android:id="@+id/img_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
</LinearLayout>
代码部分:
主类部分代码:
GalleryActivity类
package com.google.android.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Toast;
public class GalleryActivity extends Activity {
/*定义要使用的对象*/
private Gallery gallery;
private ImageView imageView;
private ImageAdapter imageadapter;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery);
/* 通过findViewById 取得 资源对象*/
gallery=(Gallery)this.findViewById(R.id.gallery);
imageView=(ImageView)findViewById(R.id.img_show);
/*给Gallery设置适配器 把GalleryActivity类传入参数*/
imageadapter=new ImageAdapter(this);
gallery.setAdapter(imageadapter);
/*设置Gallery的点击事件监听器*/
gallery.setOnItemClickListener(new Gallery.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
// TODO Auto-generated method stub
/*设置大图片*/
imageView.setBackgroundResource(imageadapter.mImageIds[position]);
/*显示该图片是几号*/
Toast.makeText(GalleryActivity.this,"你选择了"+(position)+"号图片",Toast.LENGTH_SHORT).show();
}
});
}
}
ImageAdapter 类
package com.google.android.test;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
public class ImageAdapter extends BaseAdapter{
/*变量声明*/
private Context mContext;//上下文
/* 构建一Integer array 并取得预加载Drawable 的图片id */
public Integer[] mImageIds={
R.drawable.img1,
R.drawable.img2,
R.drawable.img3,
R.drawable.img4,
R.drawable.img5
};
/*自定义的构造方法*/
public ImageAdapter(Context c){
// TODO Auto-generated constructor stub
this.mContext=c;
}
@Override
/* 重写的方法getCount,返回图片数目 */
public int getCount(){
// TODO Auto-generated constructor stub
return mImageIds.length;//获取图片的个数
}
@Override
/* 重写的方法getItemId,返回图像的数组id */
public Object getItem(int position){
// TODO Auto-generated constructor stub
return position;//获取图片在库中的位置
}
@Override
public long getItemId(int position){
// TODO Auto-generated constructor stub
return position;//获取图片在库中的位置
}
@Override
/* 重写的方法getView,返回一View 对象 */
public View getView(int position,View convertView,ViewGroup parent){
// TODO Auto-generated constructor stub
Log.i("Tag", position+"");
/* 产生ImageView 对象 */
ImageView imageView=new ImageView(mContext);
/* 设置图片给imageView 对象 */
imageView.setImageResource(mImageIds[position]);
/* 重新设置Layout 的宽高 */
imageView.setLayoutParams(new Gallery.LayoutParams(128,128));
/* 重新设置图片的宽高 */
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
/* 返回imageView 对象 */
return imageView;
}
}
[/list]
private String[] myImageURL = new String[] {
"http://static.panoramio.com/photos/iw-thumbnail/25454991.jpg",
"http://t0.gstatic.com/images?q=tbn:ANd9GcQ0TG9i0tdvE2Z5b2xuaW8jJ1u0rnYoN4ovhDxJG3BYH-pms5Y",
"http://static.panoramio.com/photos/iw-thumbnail/25454970.jpg" };
[/list]
private String[] myImageURL = new String[] {
"http://static.panoramio.com/photos/iw-thumbnail/25454991.jpg",
"http://t0.gstatic.com/images?q=tbn:ANd9GcQ0TG9i0tdvE2Z5b2xuaW8jJ1u0rnYoN4ovhDxJG3BYH-pms5Y",
"http://static.panoramio.com/photos/iw-thumbnail/25454970.jpg" };
//这是getview方法
public View getView(int position, View convertView, ViewGroup parent) {
imageView = new ImageView(mContext);
try {
URL aryURI = new URL(/blog_article/myImageURL[position]/index.html);
URLConnection conn = aryURI.openConnection();
InputStream is = conn.getInputStream();
bm = BitmapFactory.decodeStream(is);
is.close();
imageView.setImageBitmap(bm);
conn.connect();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
// 设置布局参数
imageView.setLayoutParams(new Gallery.LayoutParams(120, 120));
// 设置风格,此风格的配置是在xml中
imageView.setBackgroundResource(mGalleryItemBackground);
return imageView;
}
我想是在选中Gallery中某个图像时,在ImageSwitcher组件中放大显示该图像
请问
public void onItemSelected(AdapterView<?> parent, View view, int position,
long id){
}
[/list]
private String[] myImageURL = new String[] {
"http://static.panoramio.com/photos/iw-thumbnail/25454991.jpg",
"http://t0.gstatic.com/images?q=tbn:ANd9GcQ0TG9i0tdvE2Z5b2xuaW8jJ1u0rnYoN4ovhDxJG3BYH-pms5Y",
"http://static.panoramio.com/photos/iw-thumbnail/25454970.jpg" };
//这是getview方法
public View getView(int position, View convertView, ViewGroup parent) {
imageView = new ImageView(mContext);
try {
URL aryURI = new URL(/blog_article/myImageURL[position]/index.html);
URLConnection conn = aryURI.openConnection();
InputStream is = conn.getInputStream();
bm = BitmapFactory.decodeStream(is);
is.close();
imageView.setImageBitmap(bm);
conn.connect();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
// 设置布局参数
imageView.setLayoutParams(new Gallery.LayoutParams(120, 120));
// 设置风格,此风格的配置是在xml中
imageView.setBackgroundResource(mGalleryItemBackground);
return imageView;
}
我想是在选中Gallery中某个图像时,在ImageSwitcher组件中放大显示该图像
请问
public void onItemSelected(AdapterView<?> parent, View view, int position,
long id){
在这个方法里该怎么样 让imageviewSwitcher 放大图像呢。。
}
这个一个缩放函数,你改造一下试试看!
/**
* 缩放
*/
private void scale(double scale_width, double scale_height) {
//这种方法,有点不好是:如果图片大小超出屏幕会报错。
if((scale_width > 1 && scaleWidth * primaryWidth >= getWindowManager().getDefaultDisplay().getWidth())
|| (scale_width > 1 && scale_height * primaryHeight >= getWindowManager().getDefaultDisplay().getHeight())){
bt_bigger.setEnabled(false);
}else {
bt_bigger.setEnabled(true);
}
scaleWidth = scaleWidth * scale_width; //缩放到原来的*倍
scaleHeight = scaleHeight * scale_height;
Matrix matrix = new Matrix(); //矩阵,用于图片比例缩放
matrix.postScale((float)scaleWidth, (float)scaleHeight); //设置高宽比例(三维矩阵)
//缩放后的BitMap
Bitmap newBmp = Bitmap.createBitmap(bmp, 0, 0, primaryWidth, primaryHeight, matrix, true);
//重新设置BitMap
imageView.setImageBitmap(newBmp);
}
Bitmap b=BitmapFactory.decodeResource(CON.getResources(),R.drawable.deltio);
Bitmap bmOverlay = Bitmap.createBitmap(b.getWidth(), b.getHeight(), b.getConfig());
canvas = new Canvas(bmOverlay);
Paint paint = new Paint();
paint.setColor(Color.RED);
canvas.drawBitmap(b, new Matrix(), null);
canvas.drawCircle(750, 14, 11, paint);