import android.content.Context;
import android.graphics.Camera;
import android.graphics.Matrix;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Transformation;
import android.widget.Gallery;
 
public class MyGallery extends Gallery {
        private Camera mCamera;
        private int mWidth;
        private int mPaddingLeft;
        private boolean flag;
        private static int firstChildWidth;
        private static int firstChildPaddingLeft;
 
        /*
         * 构造方法
         */
        public MyGallery(Context context) {
                super(context);
                mCamera = new Camera();
                this.setStaticTransformationsEnabled(true);
        }
 
        /*
         * 构造方法
         */
        public MyGallery(Context context, AttributeSet attrs) {
                super(context, attrs);
                mCamera = new Camera();
                this.setStaticTransformationsEnabled(true);
        }
 
        /*
         * 构造方法
         */
        public MyGallery(Context context, AttributeSet attrs, int defStyle) {
                super(context, attrs, defStyle);
                mCamera = new Camera();
                this.setStaticTransformationsEnabled(true);
        }
 
 
        protected boolean getChildStaticTransformation(View child, Transformation t) {
                t.clear();
                t.setTransformationType(Transformation.TYPE_MATRIX);
                mCamera.save();
                final Matrix imageMatrix = t.getMatrix();
                if (flag) {
                        firstChildWidth = getChildAt(0).getWidth();
                        firstChildPaddingLeft = getChildAt(0).getPaddingLeft();
                        flag = false;
                }
                mCamera.translate(firstChildWidth / 2 + firstChildPaddingLeft + mPaddingLeft - mWidth / 2, 0f, 0f);
                mCamera.getMatrix(imageMatrix);
                mCamera.restore();
                return true;
        }
 
        protected void onSizeChanged(int w, int h, int oldw, int oldh) {
                if (!flag) {
                        mWidth = w ;
                        getLayoutParams().width = mWidth;
                        flag = true;
                }
                super.onSizeChanged(w, h, oldw, oldh);
        }
 
        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
          return super.onFling(e1, e2, 0, velocityY);//方法一:只去除翻页惯性
        }
 
        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
                // TODO Auto-generated method stub
                return super.onScroll(e1, e2, distanceX, distanceY);
        // TODO Auto-generated method stub
        }
 
}
在程序中调用MyGallery就可以实现,调用方面跟Gallery一样

gallery 从最左边开始显示并且默认选中第一个的更多相关文章

  1. vue select二级城市联动及第二级默认选中第一个option值

    当二级联动比如选择国家的时候,希望选中一个国家的时候后面城市默认选中第一个城市,则给国家的select加一个@change事件就可以了 <div class="inputLine&qu ...

  2. thymeleaf单选回显,多选回显,选回显,下拉默认选中第一个

    //默认选中第一个<input type ="radio" name="repaymentType" th:each ="repaymentTy ...

  3. pyQT Dialog默认选中某一个选项问题的解决

    方法一: 在新建ui文件时不要新建Dialog # -*- coding: utf-8 -*- # Form implementation generated from reading ui file ...

  4. Java easyui 下拉框默认选中第一个

    html代码: <tr> <td> <div style="margin-bottom:5px">计价方式:   <%--下拉框默认选中第 ...

  5. VUE 单选下拉框Select中动态加载 默认选中第一个

    <lable>分类情况</lable> <select v-model="content.tid"> <option v-for=&quo ...

  6. 对于for循环构成的九宫格里的button,如何满足“有默认选中的一个,并且只能选中一个”?

    需要构造一个全局变量self.priceBtn 在九宫格写法中 ) { self.priceBtn = btn; self.priceBtn.selected = YES; } 在button的点击方 ...

  7. jQuery设置下拉框select 默认选中第一个option

    $("#id option:first").prop("selected", 'selected');

  8. jquery 纯JS设置select下拉框,并默认选中第一个

    //html页面<select id="payWay" class="easyui-combobox" name="payWay" s ...

  9. Vue select默认选中第一个

    <td> <select v-model="selectWare"> <option selected="selected" va ...

随机推荐

  1. 管理node_modules

    http://stackoverflow.com/questions/15225865/centralise-node-modules-in-project-with-subproject

  2. 动态sql构建的过程

    基本原理:使用xsqlbuilder框架完成动态sql的构建. 基本流程:使用WebUtils.getParametersStartingWith(ServletActionContext.getRe ...

  3. Eclipse 修改字体

  4. javaTemplates-学习笔记三

    Routes入口 后台语言的应用入口都是从routes开始的,想要新建一个页面得学会配置routes. conf/routes 文件定义了全部应用URL的动作(Action),如果当浏览器请求访问ht ...

  5. 《离散数学之把妹要诀》的js实现

    网上看到一篇有意思的文章<离散数学之把妹要诀> 就用JS写了上面所讲的配对方式: 首先设定变量 // 男生理想列表 var menPreference = { A: [1, 2, 3, 4 ...

  6. MVC3 带查询的分页Helper

    接上篇mvc3 分页Helper. 带查询的分页Helper是在上一篇分页的基础上来的.下面看代码: 首先,在System.Web.Mvc命名空间下的自定义类HtmlPage下面添加一个用于处理“查询 ...

  7. 17.java.lang.CloneNotSupportedException

    java.lang.CloneNotSupportedException不支持克隆异常 当没有实现Cloneable接口或者不支持克隆方法时,调用其clone()方法则抛出该异常.

  8. 如果有三个Bool型变量,请写出一程序得知其中有2个以上变量的值是true

    下面这篇文章是从StackOverflow来的.LZ面试的时候遇到了一道面试题:“如果有三个Bool型变量,请写出一程序得知其中有2个以上变量的值是true”,于是LZ做了下面的这样的程序: bool ...

  9. mysql 5.6密码强度插件使用

    在mysql 5.6对密码的强度进行了加强,推出了validate_password 插件.支持密码的强度要求. 此插件要求版本:5.6.6 以上版本安装方式: 1.安装插件:(默认安装了插件后,强度 ...

  10. jQuery中$.each的用法

    jQuery中$.each的用法   本文导读:jQuery中each()函数是基本上所有的框架都提供了的一个工具类函数,通过它,你可以遍历对象.数组的属性值并进行处理.jQuery提供的each方法 ...