相关疑难解决方法(0)

按下动画缩小按钮尺寸,并在发布时重新获得尺寸

我想创建一个按钮,当按下按钮时会改变尺寸(稍微小一点),然后再次释放按钮后,尺寸应该变回正常尺寸.我使用Scale xml来实现这一目标,但它重新定位了自己如果我不释放按钮.

按钮在这里我指的是imageview.

这是我的源代码: -

imgSpin = (ImageView) findViewById(R.id.iv_spins);
    imgSpin.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    imgSpin.startAnimation(mAnimation);
                    spinslot();
                    break;

                case MotionEvent.ACTION_UP:
                    imgSpin.clearAnimation();
                    imgSpin.setEnabled(false);
                    break;
                }
                return true;
            }
        });
Run Code Online (Sandbox Code Playgroud)

我的规模Xml: -

<scale xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="200"
    android:fromXScale=".8"
    android:fromYScale=".8"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="1.0"
    android:toYScale="1.0" >

</scale>
Run Code Online (Sandbox Code Playgroud)

我的XML: -

 <LinearLayout
                android:id="@+id/layout_status"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight=".2"
                android:orientation="horizontal" >

                <View
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight=".5" />

                <ImageView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="2.1"
                    android:background="@drawable/bootser" />

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="2.5"
                    android:background="@drawable/bet_bg"
                    android:gravity="center_vertical"
                    android:orientation="horizontal"
                    android:weightSum="1" > …
Run Code Online (Sandbox Code Playgroud)

android ontouchlistener android-animation image-scaling

6
推荐指数
3
解决办法
4362
查看次数

触摸Android缩放按钮

我知道如何将按钮缩放到一个确定的值,但是只要用户触摸它,就有办法增加/减少每次按钮的大小吗?像这样的东西:

Button myButton = (Button)findViewById(R.id.myButton);
    myButton.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                // Some timer action here or is there a better way?
                v.setScaleX(v.getScaleX() + 0.1f);
                v.setScaleY(v.getScaleY() + 0.1f);
                return true;
            }
            else if(event.getAction() == MotionEvent.ACTION_UP) {
                v.setScaleX(1);
                v.setScaleY(1);
                return true;
            }

            return false;
        }
    });
Run Code Online (Sandbox Code Playgroud)

其他想法 - 不起作用:

    myButton.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                Timer timer = new Timer();
                TimerTask …
Run Code Online (Sandbox Code Playgroud)

android timer button scale ontouchlistener

5
推荐指数
1
解决办法
2468
查看次数