相关疑难解决方法(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 中按下按钮时增加按钮的大小

如何使按钮的大小在按下时稍微增大并在释放时再次减小?这是为了通过使用尺寸和不同的颜色来突出显示按下的按钮。

问候,琪琪

size android pressed button

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