1
我遇到以下問題: 我在android上創建了自定義視圖。我想通過縮放動畫(pivotX =「50%」和pivotY =「50%」)製作視圖脈衝。 如果視圖放置在屏幕中間,則縮放工作正常。如果視圖放置在屏幕的左側,則看起來pivotX值將爲「75%」。 如果視圖放置在屏幕的右側,則看起來pivotX值將是「25%」。自定義視圖上的縮放動畫在未放置在屏幕中間時表現不正確
這是我的看法的代碼:
public class TestView extends View
{
private Paint _paint = new Paint();
private int _x, _y;
public TestView(Context context, int x, int y)
{
super(context);
_x = x;
_y = y;
_paint.setAntiAlias(true);
_paint.setColor(Color.BLUE);
_paint.setStyle(Style.FILL);
}
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
canvas.drawCircle(_x, _y, 100 , _paint);
}
}
這裏是動畫pulse.xml文件的代碼:
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="100"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="3"
android:repeatMode="reverse"
android:toXScale="1.7"
android:toYScale="1.7" >
</scale>
片段類代碼:
ViewGroup mainLayout = (ViewGroup) getView().findViewById(R.id.my_layout);
float y = screenHeigth/2;
float x1 = screenWidth*3/4; // right hand side of the screen
dest1 = new TestView(getActivity(), x1, y);
mainLayout.addView(dest1);
float x2 = screenWidth/2; // in the middle of the screen
dest2 = new TestView(getActivity(), x2, y);
mainLayout.addView(dest2);
float x3 = screenWidth/4; // left hand side of the screen
dest3 = new TestView(getActivity(), x3, y);
mainLayout.addView(dest3);
ScaleAnimation pulse = (ScaleAnimation) AnimationUtils.loadAnimation(getActivity(), R.anim.pulse);
dest1.startAnimation(pulse);
dest2.startAnimation(pulse);
dest3.startAnimation(pulse);
我在做什麼錯?也許我必須在我的TestView類中做些什麼?
什麼PARAMS x和在TestView構造函數y代表? – pskink 2014-09-11 12:46:19
這是用於繪製特定位置上的圓圈。 - > canvas.drawCircle(_x,_y,100,_paint);圈子的座標 – manu 2014-09-11 12:56:28
和主要佈局是什麼? – pskink 2014-09-11 13:06:01