Button,ImageView都是TextView的孩子
解决方案 »
- android里面三个view怎么合并在一个空白view里面显示
- 使用registerForContextMenu()方法注册上下文菜单出现“应用程序意外停止”错误
- 很奇怪的repo start建立分支遇到的问题
- 请教Android开发
- 安卓基于socket的服务器通信为什么不可以?
- GitHub里ActiveAndroid 项目 用于SQLite的ORM框架 表自动创建问题
- 关于android中对使用自启服务的限制问题
- 用jd_gui工具反编译出来APK的代码文件变成这样子
- 关于android 滚动选择栏的实现
- 实在是不会做了checkbox的父子联动
- 程序在后台运行,达到一定条件,就会震动和铃声提醒,能实现这样的功能吗?
- Android2.0 Camera问题
package com.ray.test;import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Gallery;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;public class TestGallery extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Gallery g = (Gallery) findViewById(R.id.Gallery01);//get Gallery component
g.setAdapter(new ImageAdapter(this));//set image resource for gallery //add listener
g.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id) {
//just a test,u can start a game activity
Toast.makeText(TestGallery.this, "" + position, Toast.LENGTH_SHORT).show();
}
});
}
}=======================================================================================package com.ray.test;import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.Gallery;
//import android.widget.ImageView;
//import android.widget.RelativeLayout.LayoutParams;
import android.widget.ImageView;public class ImageAdapter extends BaseAdapter {
private Context mContext; //define Context private Integer[] mImageIds = { //picture source
R.drawable.p1,
R.drawable.p2,
R.drawable.p3,
R.drawable.p4,
R.drawable.p5,
R.drawable.p6,
R.drawable.p7,
R.drawable.p8,
}; public ImageAdapter(Context c) { //define ImageAdapter
mContext = c;
} //get the picture number
public int getCount() {
return mImageIds.length;
}
public Object getItem(int position) {
return position;
} public long getItemId(int position) {
return position;
} public View getView(int position, View convertView, ViewGroup parent) {
// ImageView i=new ImageView(mContext);
Button button=new Button(mContext);
button.setBackgroundResource(mImageIds[position]);
// button.setLayoutParams(new Gallery.LayoutParams(192,192));
// i.setImageResource(mImageIds[position]);//set resource for the imageView
button.setLayoutParams(new Gallery.LayoutParams(100, 100));//layout
button.setPadding(10, 10, 10, 10);
//i.setScaleType(ImageView.ScaleType.FIT_XY);//set scale type
return button;
}
}理论上是可行的,但是不知道代码哪里写错了
imageview extends 自 view 可能还是内部机制不一样吧