ボタンを押した際に、押したボタンのサイズを変更するサンプルプログラムを作成しています。
Y軸方向には拡大されるのですが、X軸方向に拡大してくれません。
Y軸同様にX軸も処理していると思っているのですが、何か特別な処理が必要なのでしょうか。
---MainActivity.java--- package com.sample.animation; import android.animation.ObjectAnimator; import android.animation.PropertyValuesHolder; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btn = (Button)findViewById(R.id.btn1); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { animatePropertyValuesHolderSample((Button)v, v.getScaleX(), v.getScaleY(), (float)2); } }); } /** * @param target * @param fromX * @param fromY * @param scaleRatio */ private void animatePropertyValuesHolderSample( Button target, float fromX, float fromY, float scaleRatio ) { float toSizeX = 1.5f; float toSizeY = fromY * scaleRatio; // scaleX プロパティを変化 PropertyValuesHolder holderX = PropertyValuesHolder.ofFloat( "scaleX ", fromX, toSizeX ); // scaleYプロパティを変化 PropertyValuesHolder holderY = PropertyValuesHolder.ofFloat( "scaleY", fromY, toSizeY ); // targetに対してholderX, holderY を実行させます ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder( target, holderX, holderY ); // 2秒かけて実行 objectAnimator.setDuration( 2000 ); // アニメーションを開始します objectAnimator.start(); } }
---activity_main.xml--- <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:orientation="vertical" tools:context="com.sample.animation.MainActivity"> <Button android:id="@+id/btn1" android:layout_width="200dp" android:layout_height="80dp" android:layout_margin="10dp" android:text="1300点・2600点"/> </LinearLayout>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。