引用public class SamplePopup extends Activity { PopupWindow popup; //GridView gView; GridView gView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); final LinearLayout musicGrid = (LinearLayout) inflater.inflate(R.layout.gridviewpopup, null, false); gView = (GridView) musicGrid.findViewById(R.id.gridview); gView.setAdapter(new ImageAdapter(this)); <SPAN style="COLOR: #ff00ff"> popup = new PopupWindow(this); popup.setContentView(musicGrid); popup.setTouchable(true);</SPAN> <SPAN style="COLOR: #ff0000"> popup.setFocusable(true);</SPAN> gView.setOnItemClickListener(new Gallery.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { Log.i("huhudhufhud",""); // popup.showAsDropDown(findViewById(R.id.main)); <SPAN style="COLOR: #ff00ff">popup.dismiss();</SPAN> } }); final Button popupButton = (Button) findViewById(R.id.popup); popupButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { <SPAN style="COLOR: #ff00ff"> popup.setWidth(300); popup.setHeight(200); popup.showAtLocation(findViewById(R.id.main), Gravity.CENTER, 0, 0);</SPAN> } }); } }
粉红色部分就是vpopupwindow要使用的,红色的部分一定要添加 不然点击事件不执行。
layout.gridviewpopup 如下:
[code="java<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridviewparent"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:paddingTop="10dip"
android:paddingBottom="10dip"
android:gravity="center_horizontal" >
<GridView
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:verticalSpacing="30dp"
android:horizontalSpacing="15dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
</LinearLayout>
引用
main
引用<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/main" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Button android:id="@+id/popup" android:scaleType="centerInside" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="POPUP" /> </LinearLayout>
attrsl:
引用<?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="Gallery1"> <attr name="android:galleryItemBackground" /> </declare-styleable> </resources>
这个呢只是图片的一个外边框背景。
ImageAdapter的扩展
引用public class ImageAdapter extends BaseAdapter { private Context mContext; private int itemBackground; public ImageAdapter(Context c) { mContext = c; //---setting the style--- <SPAN style="COLOR: #ffcc00">TypedArray a = c.obtainStyledAttributes(R.styleable.Gallery1); itemBackground = a.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle();</SPAN> } public int getCount() { return images.length; } public Object getItem(int position) { //return images[position]; return position; } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { ImageView imageView; if (convertView == null) { imageView = new ImageView(mContext); } else { imageView = (ImageView) convertView; } imageView.setImageResource(images[position]); imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); <SPAN style="COLOR: #ffcc00">imageView.setBackgroundResource(itemBackground);</SPAN> return imageView; } public Integer[] images = { R.drawable.android, R.drawable.icon, R.drawable.android }; }
发表评论
-
初学Android,Intent概要(十一) .
2012-08-11 14:01 785下面内容我觉得归纳的很好,我看了几本书,包括一些英文的,写 ... -
初学Android,字符串,数字,尺寸,数组资源(十二) .
2012-08-11 00:09 1339下面是使用字符串,数字,尺寸,数组资源的例子,挺好,一个例子已 ... -
初学Android,使用Drawable资源之使用StateListDrawable资源(十三) .
2012-08-11 00:06 1137StateListDrawable用于组织多个Drawable ... -
初学Android,使用Drawable资源之使用LayerDrawable资源(十四)
2012-08-03 10:27 754LayerDrawable,系统将会按这些Drawable对象 ... -
初学Android,使用Drawable资源之使用ShapeDrawable资源(十五)
2012-08-03 14:40 1092ShapeDrawable比较简单,用来定义一个基本几何图形, ... -
初学Android,使用Drawable资源之使用ClipDrawable资源(十六)
2012-08-03 16:23 1029ClipDrawable代表从其它位图上截取一个"图 ... -
初学Android,使用Drawable资源之使用AnimationDrawable资源(十七)
2012-08-06 11:34 920这次学学怎么使用动画资源,AnimationDrawable, ... -
初学Android,使用自定义的XML资源(十八)
2012-08-06 15:16 670使用自定义的XML资源,这当然也必须是Android的一个功能 ... -
初学Android,使用菜单资源(十九)
2012-08-07 17:16 686Android里面也可用XML定义菜单资源,菜单分两种,一种是 ... -
初学Android,使用样式(style)资源(二十)
2012-08-09 09:57 748在Android里面,样式的概念跟网页中CSS样式表的概念相似 ... -
初学Android,使用主题(Theme)资源(二十一)
2012-08-09 11:06 720主题跟样式类似,也是放在路径/res/values下同样以&l ... -
初学Android,使用属性(Attribute)资源(二十二)
2012-08-09 14:47 778感觉这篇写的不错,拿来转了 http://wujia ... -
初学Android,使用原始资源(二十三)
2012-08-09 17:09 771原始资源就是Android没有为之提供专门支持的资源文件,可以 ... -
requestWindowFeature类
2012-08-09 17:21 730requestWindowFeature可以设 ... -
android学习笔记(二)
2012-08-08 12:00 697Activities and Tasks 一个活动能启动另一 ... -
Android之SurfaceView学习(一)
2012-08-07 16:57 623首先我们先来看下官方API对SurfaceView的介绍 S ... -
adnroid 学习笔记(一)
2012-08-06 16:10 606今天开始学习android,在配置资源文件时遇到的问题,在这里 ...
相关推荐
Android 自定义ImageAdapter构造器,实现手指控制图片左右滑动效果,范例需使用比较多的class 类,请一个一个引入。 实现的原理是 添加一ImageAdapter并设置给Gallery对象,设置一个itemclickListener并Toast被...
效果1:效果2:效果3:效果4:效果5:使用说明:imageList=(ListView)findViewById(R.id.image_list); imageAdapter=new ImageAdapter(); imageList.getListView().setAdapter(imageAdapter); imageList....
在Android程序中很多客户端软件和浏览器软件都喜欢用Tab分页标签来搭建界面框架。读者也许会马上想到使用TabHost 与 TabActivity的组合,其实最常用的不是它们,而是由GridView与ActivityGroup的组合。每当用户在...
前言 很多人要实现轮播图都会想到使用ViewPager + Handler来完成轮播图的效果。但是在RxJava快速发展的情况下,已经可以使用RxJava来代替Handler完成这样...private class ImageAdapter extends PagerAdapter{ priva
这里主要通过自定义Gallery和ImageAdapter(继承自BaseAdapter)实现 1、倒影绘制 ImageAdapter继承自BaseAdapter,详细实现可见前面关于Android Gallery的用法。这里重点介绍倒影原理及实现 倒影原理: 倒影效果是...
本文实例讲述了Android编程实现的超炫图片浏览器。分享给大家供大家参考,具体如下: 使用过Android自带的gallery组件的人都知道,gallery实现的效果就是拖动浏览一组图片,相比iphone里也是...传入参数为context和程
首先这里先声明引用了开源库viewflow,我这里只用了其中的ViewFlow和CircleFlowIndicator。想对viewflow有更多了解的可以去github下载... 我写的ImageAdapter,图片直接在资源文件中,实际应用时应该是从网络获取。
Jh_ImageAdapter 一个友好的模拟映像适配器,这样即使您没有拉下媒体目录,您的本地环境也不会掉队。安装composer require --dev wearejh/m2-module-image-adapter它有什么作用? 原理部分是一个新的图像适配器(一...
此Android工程通过在ImageAdapter里加入Gallery,实现了图片拖动效果,并通过ScaleAnimation实现了点击某个图片使其放大的功能。
gallery3D的简单例子实现:代码文件包括 -----Gallery3DActivity -----GalleryFlow -----ImageAdapter
主程序有两大重点:一是ImageAdapter继承BaseAdapter class的未实现方法的重写构造;二是Gallery的OnItemClick()方法与图片及Layout宽高设置。
而后在使用过程中,发现了有两点可以改进: (1)初始图片位于中间,左边空了一半空间,比较难看,可以改为重复滚动地展示; (2)由于图片一开始就需要加载出来,所以对内存开销较大,很容易OOM,需要对图片的内存...
gallery.setAdapter(new ImageAdapter(this)); gallery.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> adapter, View view, int ...
public class ImageAdapter extends BaseAdapter { int mGallerystyle; public ImageAdapter(Context c) { mContext = c; TypedArray a = obtainStyledAttributes(R.styleable.Gallery); ...
viewpager的无限轮播有两种办法 一、Integer.MAX_VALUE 原理是将Adapter的getCount返回Integer.MAX_VALUE,然后让viewpager的初始位置定位到Integer.MAX_...public class ImageAdapter extends PagerAdapter { pri
阿里巴巴weex校园开发大赛作品该app获得比赛第二名weex开发流程1.打开Android Studio,初始化一个项目2....compile 'com.android.support:recyclerview-v7:24.2.1' compile 'com.android.support:appcompat-v7:24.2.1' compile 'com.alibaba:fastjson:1.1.45' compile 'com.taobao.android:weex_sdk:0.8.0@aar' compile 'com.squareup.picasso:2.5.2'3.利用Picasso实现ImageAdapterpublic class ImageAdapter
线性布局:lineerlayout,相对布局:relativeLayout,表格布局:tablelayout,列表布局:listview(listAdapter),表格布局:gridview(listadapter),imageadapter,绝对布局:absoluteLayout,标签布局:tablayout:1>android....
public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener, AdapterView.OnItemLongClickListener, ImageAdapter.OnImageCheckListener, View.OnClickListene
Android开发图片滚动效果,供大家参考,具体内容如下 效果图: 设置适配来设置图片位置大小 ... import android.content.Context; import android.view.View;...import android.view.... public class ImageAdapter extend