안드로이드에서 뷰를 만들었으므로 애니메이션을 아래에서 위로 또는 그 반대로 움직여야합니다. 나는 TranslateAnimation을 사용하여이 작업에 성공했다. 그러나 문제는보기에 몇 개의 단추가 있다는 것입니다. 움직이는 지점에서 터치 지점은 원래 위치에 남아 있으며 새 위치로 이동하지 않습니다. 그래서 버튼의 원래 위치를 다시 클릭하면 맨 아래 애니메이션이 실행되지만 버튼은 거기에 존재하지 않습니다.애니메이션 후 버튼이 작동하지 않습니다. android
나는 인터넷을 검색했고 사람들은 매개 변수를 사용하여 view.layout을 호출한다고 말하고 있지만 애니메이션 시작 및 애니메이션 끝 부분에서 가져 오기를 시도했기 때문에 내 질문은 뷰의 최신 위치를 얻는 방법입니다. 그것은 동일하게 유지됩니다.
또한 실제로는 검색 결과를 복사하지 않고 이동하는 등의 답변을주지 마십시오. 검색했지만 적절한 솔루션을 찾을 수 없거나 구현되지 않았기 때문입니다. 여기
코드입니다 :import android.content.Context;
import android.graphics.Matrix;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.Transformation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import com.Card_Android.R;
public class GameMenuScreenAnimated extends LinearLayout {
private final View mainView;
public GameMenuScreenAnimated(Context context,
final GameViewController dashboardVC) {
super(context);
LayoutInflater inflater = LayoutInflater.from(context);
mainView = inflater.inflate(R.layout.main_menu, this);
ImageButton btn = (ImageButton) mainView.findViewById(R.id.trade);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("yaaaaaay!!!!");
}
});
slideDown(mainView);
}
public View getMainView() {
return mainView;
}
private void slideUp(final View view) {
Animation slide = new TranslateAnimation(Animation.RELATIVE_TO_SELF,
0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
0.5f);
slide.setDuration(1000);
slide.setFillAfter(true);
slide.setFillEnabled(true);
view.startAnimation(slide);
slide.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
int[] startPosition = new int[2];
view.getLocationOnScreen(startPosition);
System.out.println("onAnimationStart " + startPosition[0]
+ " , " + startPosition[1]);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
int[] endPosition = new int[2];
view.getLocationOnScreen(endPosition);
System.out.println("onAnimationEnd " + endPosition[0] + " , "
+ endPosition[1]);
}
});
}
private final AnimationListener slideDownAnimationListener = new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
final int left = mainView.getLeft();
final int top = mainView.getTop();
final int right = mainView.getRight();
final int bottom = mainView.getBottom();
mainView.layout(left, (int) Math.round(top + 0.25 * top), right,
(int) Math.round(bottom + 0.25 * bottom));
}
};
private final Animation slideDownAnimation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.25f);
private void slideDown(final View view) {
slideDownAnimation.setDuration(1000);
slideDownAnimation.setFillAfter(true);
slideDownAnimation.setFillEnabled(true);
slideDownAnimation.setAnimationListener(slideDownAnimationListener);
view.startAnimation(slideDownAnimation);
}
}
는 XML :
이<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="bottom"
>
<LinearLayout
android:id="@+id/tableLayout1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="center"
>
<ImageButton
android:id="@+id/trade"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="0dp"
android:background="@null"
android:scaleType="centerCrop"
android:src="@drawable/upgrade_btn" />
</LinearLayout>
<LinearLayout
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:gravity="center"
android:layout_height="wrap_content"
>
<ImageButton
android:id="@+id/evolution"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:background="@null"
android:scaleType="centerCrop"
android:src="@drawable/sell_btn" />
<ImageButton
android:id="@+id/trade"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:background="@null"
android:scaleType="centerCrop"
android:src="@drawable/upgrade_btn"
/>
</LinearLayout>
</LinearLayout>
내가하고 싶은 모든이
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/evolution">
<item android:state_pressed="true" android:drawable="@drawable/menu_off" /> <!-- pressed -->
<item android:state_focused="true" android:drawable="@drawable/menu_on" /> <!-- focused -->
<item android:drawable="@drawable/menu_on" /> <!-- default -->
</selector>
가 작성하는 당김 XML은 몇 가지 간단한 메뉴입니다 단추를 클릭하고 밖으로 미끄러지는 단추.
아니요 xml? 코드 없어요? –
여기 있습니다! 코드를 추가했습니다. –
btw 거기에 내가 언급 havent 다른 두 개의 drwable xml 이미지가 거의 동일하게 변경된 차이가 있습니다. –