`
chenqiang5206
  • 浏览: 32492 次
  • 性别: Icon_minigender_1
  • 来自: 江西
社区版块
存档分类

ImageAdapter和PopupWindow的使用

 
阅读更多
引用
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 自定义ImageAdapter 图片左右滑动效果.rar

    Android 自定义ImageAdapter构造器,实现手指控制图片左右滑动效果,范例需使用比较多的class 类,请一个一个引入。  实现的原理是 添加一ImageAdapter并设置给Gallery对象,设置一个itemclickListener并Toast被...

    pulltorefresh:基于viewdraghelper实现的下拉刷新组件,集成了下拉刷新,底部加载更多,数据初始加载显示loading等功能

    效果1:效果2:效果3:效果4:效果5:使用说明:imageList=(ListView)findViewById(R.id.image_list); imageAdapter=new ImageAdapter(); imageList.getListView().setAdapter(imageAdapter); imageList....

    Android入门之ActivityGroup+GridView实现Tab分页标签的方法

    在Android程序中很多客户端软件和浏览器软件都喜欢用Tab分页标签来搭建界面框架。读者也许会马上想到使用TabHost 与 TabActivity的组合,其实最常用的不是它们,而是由GridView与ActivityGroup的组合。每当用户在...

    Android中用RxJava和ViewPager实现轮播图

    前言 很多人要实现轮播图都会想到使用ViewPager + Handler来完成轮播图的效果。但是在RxJava快速发展的情况下,已经可以使用RxJava来代替Handler完成这样...private class ImageAdapter extends PagerAdapter{ priva

    Android编程滑动效果之倒影效果实现方法(附demo源码下载)

    这里主要通过自定义Gallery和ImageAdapter(继承自BaseAdapter)实现 1、倒影绘制 ImageAdapter继承自BaseAdapter,详细实现可见前面关于Android Gallery的用法。这里重点介绍倒影原理及实现 倒影原理: 倒影效果是...

    Android编程实现的超炫图片浏览器

    本文实例讲述了Android编程实现的超炫图片浏览器。分享给大家供大家参考,具体如下: 使用过Android自带的gallery组件的人都知道,gallery实现的效果就是拖动浏览一组图片,相比iphone里也是...传入参数为context和程

    viewflow实现类似淘宝,网易新闻的横幅banner,可循环自动播放

    首先这里先声明引用了开源库viewflow,我这里只用了其中的ViewFlow和CircleFlowIndicator。想对viewflow有更多了解的可以去github下载... 我写的ImageAdapter,图片直接在资源文件中,实际应用时应该是从网络获取。

    m2-module-image-adapter:Magento 2的模拟图像适配器

    Jh_ImageAdapter 一个友好的模拟映像适配器,这样即使您没有拉下媒体目录,您的本地环境也不会掉队。安装composer require --dev wearejh/m2-module-image-adapter它有什么作用? 原理部分是一个新的图像适配器(一...

    Android图片拖动、点击放大效果

    此Android工程通过在ImageAdapter里加入Gallery,实现了图片拖动效果,并通过ScaleAnimation实现了点击某个图片使其放大的功能。

    gallery3D简单例子实现

    gallery3D的简单例子实现:代码文件包括 -----Gallery3DActivity -----GalleryFlow -----ImageAdapter

    相片集---Gallery与衍生BaseAdapter

    主程序有两大重点:一是ImageAdapter继承BaseAdapter class的未实现方法的重写构造;二是Gallery的OnItemClick()方法与图片及Layout宽高设置。

    Android实现CoverFlow效果控件的实例代码

    而后在使用过程中,发现了有两点可以改进: (1)初始图片位于中间,左边空了一半空间,比较难看,可以改为重复滚动地展示; (2)由于图片一开始就需要加载出来,所以对内存开销较大,很容易OOM,需要对图片的内存...

    android图片拍照 删除 添加 旋转

    gallery.setAdapter(new ImageAdapter(this)); gallery.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView&lt;?&gt; adapter, View view, int ...

    Android Gallery控件实现图片浏览源代码

    public class ImageAdapter extends BaseAdapter { int mGallerystyle; public ImageAdapter(Context c) { mContext = c; TypedArray a = obtainStyledAttributes(R.styleable.Gallery); ...

    viewpager的无限滑动

    viewpager的无限轮播有两种办法 一、Integer.MAX_VALUE 原理是将Adapter的getCount返回Integer.MAX_VALUE,然后让viewpager的初始位置定位到Integer.MAX_...public class ImageAdapter extends PagerAdapter { pri

    weex-android-joke:一个由阿里巴巴的weex提供支持的笑话android应用

    阿里巴巴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

    android核心组件(1)常用布局,adapter,handler,UI

    线性布局:lineerlayout,相对布局:relativeLayout,表格布局:tablelayout,列表布局:listview(listAdapter),表格布局:gridview(listadapter),imageadapter,绝对布局:absoluteLayout,标签布局:tablayout:1&gt;android....

    详解android写一个选择图片的示例代码

    public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener, AdapterView.OnItemLongClickListener, ImageAdapter.OnImageCheckListener, View.OnClickListene

    Android实现图片滚动效果

    Android开发图片滚动效果,供大家参考,具体内容如下 效果图: 设置适配来设置图片位置大小 ... import android.content.Context; import android.view.View;...import android.view.... public class ImageAdapter extend

Global site tag (gtag.js) - Google Analytics