点击Gallery弹出对应的Gallery大图

2024-06-24 04:18

本文主要是介绍点击Gallery弹出对应的Gallery大图,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

今天遇到了这么一个问题,给3个相应的缩略图,点击缩略图弹出的相应的缩略图片的大图。


解决办法:setSelection,注意这个方法是Gallery的。(下面代码功能:缩略图可以左右滑动;弹出大图可以左右滑动;点A缩略图,显示A大图。点击B大图,显示B大图。并且 不影响滑动)


代码:我的代码有点长,如果你已经有思路,就直接去百度一下setSelection();

1. xml代码:(三张缩略图)

<HorizontalScrollView//让三张图片左右滑动
    android:id="@+id/hsv"
    android:layout_width="match_parent"
    android:layout_height="220px"
    android:background="@color/white"
    android:scrollbars="none">

    <LinearLayout
        android:id="@+id/linear"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="20px"
        android:layout_marginTop="20px"
        android:background="@color/white"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        >

        <ImageView
            android:id="@+id/image_details_certificate_image_1"
            android:layout_width="250px"
            android:layout_height="180px"
            android:layout_marginLeft="20px"
            android:scaleType="fitXY"
            android:src="@drawable/test_photo"
            ></ImageView>

        <ImageView
            android:id="@+id/image_details_certificate_image_2"
            android:layout_width="250px"
            android:layout_height="180px"
            android:layout_marginLeft="20px"
            android:scaleType="fitXY"
            android:src="@drawable/test_photo"
            ></ImageView>

        <ImageView
            android:id="@+id/image_details_certificate_image_3"
            android:layout_width="250px"
            android:layout_height="180px"
            android:layout_marginLeft="20px"
            android:layout_marginRight="20px"
            android:scaleType="fitXY"
            android:src="@drawable/test_photo"
            ></ImageView>
    </LinearLayout>

</HorizontalScrollView>

2. 把他们都findViewById之后,设置点击事件:

OnTouchListener listener = new OnTouchListener() {@Override
    public boolean onTouch(View arg0, MotionEvent arg1) {switch (arg1.getAction()) {case MotionEvent.ACTION_UP:switch (arg0.getId()) {case R.id.image_details_certificate_image_1:iv_image_1.setBackgroundColor(Color.parseColor("#ffffff"));
                        tag = "1";
                        startHintPopup("证书及文件");//我是用的PopupWindow来做的弹出大图
                        break;
case R.id.image_details_certificate_image_2: iv_image_2.setBackgroundColor(Color.parseColor("#ffffff")); tag = "2"; startHintPopup("证书及文件"); break; case R.id.image_details_certificate_image_3: iv_image_3.setBackgroundColor(Color.parseColor("#ffffff")); tag = "3"; startHintPopup("证书及文件"); break; } break; case MotionEvent.ACTION_CANCEL: switch (arg0.getId()) { case R.id.top_back_view: top_back.setAlpha(255); break; case R.id.cash_coupon_bg: cash_coupon_bg.setBackgroundColor(Color.parseColor("#ffffff")); break; } break; } return true; }};iv_image_1.setOnTouchListener(listener);iv_image_2.setOnTouchListener(listener);iv_image_3.setOnTouchListener(listener);

3. new一个PopupWindow,写一个要显示在PopupWindow上面的布局,这个布局就是显示大图Gallery,我另外在布局添加了一个TextView,不影响阅读

先贴xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:id="@+id/ll_root"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    >

    <Gallery
        android:id="@+id/gl_photo"
        android:layout_width="720px"
        android:layout_height="450px"
        android:spacing="20px"
        />

    <TextView
        android:id="@+id/tv_photo"
        android:layout_width="720px"
        android:layout_height="30px"
        android:background="@color/white"
        android:gravity="center_horizontal"
        android:padding="10px"
        android:textColor="@color/black"
        android:textSize="25px"/>

</LinearLayout>

4. 这是点击缩略图,弹出PopupWindow显示大图,并且可以任意滑动

public synchronized void startHintPopup(String s) {if (mPopupWindow == null) {v_photo = LayoutInflater.from(this).inflate(R.layout.large_photo_slide, null);
        LinearLayout linear = (LinearLayout) v_photo.findViewById(R.id.ll_root);
        photo_image = (Gallery) v_photo.findViewById(R.id.gl_photo);
        photo_text = (TextView) v_photo.findViewById(R.id.tv_photo);//这是刚刚您看的xml,让他把代码关联起来。下面各种LayoutParams就是给这个xml布局设置属性,看不懂就不用看了,可以直接看下面的PopupWindow
        ViewGroup.LayoutParams p = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        linear.setLayoutParams(p);

        LinearLayout.LayoutParams p_image = new LinearLayout.LayoutParams(Layout.getScale(720), Layout.getScale(500));
        photo_image.setLayoutParams(p_image);

        LinearLayout.LayoutParams p_text = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        p_text.gravity = Gravity.CENTER_HORIZONTAL;
        photo_text.setLayoutParams(p_text);
        Layout.setTextViewSize(photo_text, 30);

        mPopupWindow = new PopupWindow(v_photo, RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT, true);mPopupWindow.setBackgroundDrawable(res.getDrawable(R.drawable.image_backgrund));//把PopupWindow的背景色设置成半透明mPopupWindow.setAnimationStyle(R.style.ImageDialogStyle);//这个是PopupWindow的动画及属性,代码贴在下面,也可以忽略

    }//下面绿色的就是今天的主角,就是靠他,点A缩略图,显示A大图。点击B大图,显示B大图。并且不影响滑动。photo_image.setAdapter(new All_certifAdapter(this, item.all_certif, tag));if(tag.equals("1")){photo_image.setSelection(0);//让Adapter里的position显示对应点击的--大图}if(tag.equals("2")){photo_image.setSelection(1);}if(tag.equals("3")){photo_image.setSelection(2);}photo_text.setText(s);

    // 设置好参数之后再show
    mPopupWindow.showAtLocation(v_photo, Gravity.CENTER, 0, 0);
}

5. 下面3块代码是给PopupWindow设置的属性

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="ImageDialogStyle" parent="android:Theme.Dialog">
        <item name="android:windowBackground">@color/back</item>
        <item name="android:windowFrame">@null</item><!--无边框-->·<item name="android:windowNoTitle">true</item><!--没有标题-->
        <item name="android:windowIsFloating">true</item><!--是否浮在activity之上-->
        <item name="android:windowIsTranslucent">true</item><!--背景是否半透明-->
        <item name="android:windowContentOverlay">@null</item><!--对话框是否有遮盖 -->
        <item name="android:windowAnimationStyle">@style/AnimHead</item><!--动画样式-->
        <item name="android:backgroundDimEnabled">true</item><!--背景是否模糊-->
        <item name="android:windowFullscreen">true</item><!-- 设置全屏显示 -->
        <item name="android:windowCloseOnTouchOutside">true</item>
    </style>

    <style name="AnimHead" parent="@android:style/Animation">
        <item name="android:windowEnterAnimation">@anim/head_in</item>//弹出动画贴在下面
        <item name="android:windowExitAnimation">@anim/head_out</item>//消失动画贴在下面
    </style>
</resources>

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha
        android:duration="200"
        android:fromAlpha="0"
        android:toAlpha="1"/>

    <scale
        android:duration="200"
        android:fromXScale="0"
        android:fromYScale="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="1"
        android:toYScale="1"/>

</set>

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">

    <alpha
        android:duration="200"
        android:fromAlpha="1"
        android:toAlpha="0"/>

    <scale
        android:duration="500"
        android:fromXScale="1"
        android:fromYScale="1"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="0"
        android:toYScale="0"/>
</set>


6. 这是最后的步骤:Gallery的Adapter

public class All_certifAdapter extends BaseAdapter {private Context context;
    private List<String> dataList;
    private final String tag;
    private ImageLoader mImageLoader;

    public All_certifAdapter(Context context, List<String> list, String tag) {this.context = context;
        this.dataList = list;
        this.tag = tag;
        mImageLoader = new ImageLoader(context);
    }public int getCount() {return dataList.size();
    }public String getItem(int position) {return dataList.get(position);
    }public long getItemId(int position) {return position;
    }public View getView(int position, View convertView, ViewGroup parent) {ImageView iv = new ImageView(context);
        iv.setBackgroundColor(0xFFFFFFFF);

        if (tag.equals("1")) {mImageLoader.DisplayImage(dataList.get(position), iv, R.drawable.test_photo);
        }if (tag.equals("2")) {mImageLoader.DisplayImage(dataList.get(position), iv, R.drawable.test_photo);
        }if (tag.equals("3")) {mImageLoader.DisplayImage(dataList.get(position), iv, R.drawable.test_photo);
        }iv.setScaleType(ImageView.ScaleType.FIT_XY);
        iv.setLayoutParams(new Gallery.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        return iv;
    }
}

这篇关于点击Gallery弹出对应的Gallery大图的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1089144

相关文章

加载网络图片显示大图

1.将图片的uri列表和下标传给ImagePagerActivity public void imageBrower(int position, ArrayList<String> urls2) {Intent intent = new Intent(this, ImagePagerActivity.class); intent.putExtra(ImagePagerActivity

HashSet的存储方式是把HashMap中的Key作为Set的对应存储项。

在 Java2中,有一套设计优良的接口和类组成了Java集合框架Collection,使程序员操作成批的数据或对象元素极为方便。这些接口和类有很多对抽象数据类型操作的API,而这是我们常用的且在数据结构中熟知的。例如Map,Set,List等。并且Java用面向对象的设计对这些数据结构和算法进行了封装,这就极大的减化了程序员编程时的负担。程序员也可以以这个集合框架为基础,定义更高级别的数据

玩转Web之easyui(二)-----easy ui 异步加载生成树节点(Tree),点击树生成tab(选项卡)

关于easy ui 异步加载生成树及点击树生成选项卡,这里直接给出代码,重点部分代码中均有注释 前台: $('#tree').tree({ url: '../servlet/School_Tree?id=-1', //向后台传送id,获取根节点lines:true,onBeforeExpand:function(node,param){ $('#tree').tree('options'

和、字母数字对应的ASCII码。

打印A、Z;a z   0   9对应的ASCII码。 System.out.println("A:"+(int)'A');System.out.println("Z:"+(int)'Z');System.out.println("--------------------------");System.out.println("a:"+(int)'a');Sy

Web项目部署后浏览器刷新返回Nginx的404错误对应解决方案

data: 2024/6/22 16:05:34 周六 limou3434 叠甲:以下文章主要是依靠我的实际编码学习中总结出来的经验之谈,求逻辑自洽,不能百分百保证正确,有错误、未定义、不合适的内容请尽情指出! 文章目录 1.源头2.排错3.原因4.解决 概要:… 资料:本文参考了 这份博文您可前去一看。 1.源头 在帮朋友部署和测试项目的时候,遇

数据结构历年考研真题对应知识点(栈)

目录 3.1栈 3.1.1栈的基本概念 【栈的特点(2017)】 【入栈序列和出栈序列之间的关系(2022)】  【特定条件下的出栈序列分析(2010、2011、2013、2018、2020)】 3.1.2栈的顺序存储结构 【出/入栈操作的模拟(2009)】 3.1栈 3.1.1栈的基本概念 【栈的特点(2017)】 栈(Stack)是只允许在一端进行插入或删除操作的

腾讯面试题:根据上排给出的十个数,在其下排填出对应的十个数。

版权所有。所有权利保留。 欢迎转载,转载时请注明出处: http://blog.csdn.net/xiaofei_it/article/details/17172769 根据上排给出的十个数,在其下排填出对应的十个数,要求下排每个数都是先前上排那十个数在下排出现的次数。 上排的十个数如下: 0,1,2,3,4,5,6,7,8,9

C#弹出新的窗体在点击处的正下方出现

例如在做很多C#窗体程序的登录时,往往不希望再格外弹出一个登录窗体,那么这是我们让弹出的登录框更不显得很突兀,需要我们去掉登陆框的边框,同时需要确定弹出对话框的位置。 步骤如下: 1、新建一个窗体Form2,并在属性里将FormBorderStyle设为None 2、在跳转按钮方法里添加如下代码:       Form2 f2 = new Form2();             Poin

AJAX实现不刷新页面点击按钮在目标位置加载目标内容

AJAX可以实现异步请求数据,即不刷新页面的情况下请求服务器,加载目标内容到页面。 AJAX 不是新的编程语言,而是一种使用现有标准的新方法。 AJAX 是与服务器交换数据并更新部分网页的艺术,在不重新加载整个页面的情况下 AJAX主要使用XMLHttpRequest对象来实现异步地与服务器交换数据,XMLHttpRequest 对象如果要用于 AJAX 的话,其 open() 方法