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. hdu 2604Queuing dp+ 矩阵快速幂

    题目链接 给一个长度为n的字符串, 每个字符可以使f或m. 问你不包含子串fmf以及fff的字符串数量有多少. 令0表示mm结尾, 1表示mf, 2表示ff, 3表示fm. 那么 f(n+1, 0) ...

  2. 简单的实现树莓派的WEB控制

    最终效果如图: 用到的知识:Python Bottle HTML Javascript JQuery Bootstrap AJAX 当然还有 linux 我去,这么多--我还是一点一点说起吧-- 先贴 ...

  3. atoi函数和atof函数

    1.函数名:atoi 功能:是把字符串转换成整型数的一个函数,应用在计算机程序和办公软件中 名字来源:alphanumeric to integer 用法:int atoi(const char *n ...

  4. MySQLdb的安装

    第一步:下载安装介质 https://pypi.python.org/pypi/MySQL-python 注意虽然模块名叫MySQLdb但是MySQL-python指的就是MySQLdb 第二步:安装 ...

  5. 可以把一堆dll文件放到程序目录下的一个自建目录里面

    窦宁波大哥哥的那篇文章的这种写法还是很有参考价值的. QString strLibPath(QDir::toNativeSeparators(QApplication::applicationDirP ...

  6. 清风注解-Swift程序设计语言:Point1~5

    目录索引 清风注解-Swift程序设计语言 Point 1. Swift 风格的"Hello, world" 代码事例: println("Hello, world&qu ...

  7. word-wrap,white-space和text-overflow属性

    (1) //在断点处换行 word-wrap: normal; //允许在长单词进行换行 word-wrap: break-word; (2) white-space:怎么处理元素间的空白 white ...

  8. UVa 10330 - Power Transmission(最大流--拆点)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  9. OS笔记047代理传值和block传值

    在两个不同的控制器之间传递数据,可以使用代理传值或者block传值. 例子是一个简单通讯录. 主界面如下: 添加联系人界面 查看/编辑联系人界面:默认是查看模式,点击编辑后进入编辑模式 编辑模式 数据 ...

  10. SQLite 终端相关命令

    SQLite ALL Last login: Fri Dec  5 09:52:08 on ttys002 BeSilent:~ qianfeng$ sqlite3 data.db SQLite ve ...