मैं दो बटनों की स्थिति स्वैप करने की कोशिश कर रहा हूं। मेरे अदला-बदली कोड दिखाई देता है:दो बटनों की एनिमेटेड स्वैप स्थिति
private void exchangeButtons(Button btn1, Button btn2) {
// Create the animation set
AnimationSet exchangeAnimation = new AnimationSet(true);
TranslateAnimation translate = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, btn2.getLeft(),
Animation.RELATIVE_TO_SELF, btn1.getLeft(),
Animation.RELATIVE_TO_SELF, btn2.getRight(),
Animation.RELATIVE_TO_SELF, btn1.getRight());
translate.setDuration(500);
exchangeAnimation.addAnimation(translate);
//int fromX = btn1.getLeft();
//int fromY = btn1.getRight();
//int toX = btn2.getLeft();
//int toY = btn2.getRight();
Log.d("ArrangeMe",
"view1 pos:" + btn1.getLeft() + ",
" +btn1.getRight() + "view2 pos:" +
btn2.getLeft() + ", " + btn2.getRight());
AnimationSet exchangeAnimation1 = new AnimationSet(true);
TranslateAnimation translate1 = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, btn1.getLeft(),
Animation.RELATIVE_TO_SELF, btn2.getLeft(),
Animation.RELATIVE_TO_SELF, btn1.getRight(),
Animation.RELATIVE_TO_SELF, btn2.getRight());
translate1.setDuration(500);
exchangeAnimation1.addAnimation(translate1);
// EXECUTE btn1.startAnimation(exchangeAnimation);
btn2.startAnimation(exchangeAnimation1);
}
मैं के रूप में नीचे दिए गए कोड को फोन:
exchangeButtons(button1, button2);
मेरे लेआउट के रूप में नीचे दिखता है:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:text="One"
android:id="@+id/button1"
android:layout_height="70px"
android:layout_width="70px"
android:layout_weight="1">
</Button>
<Button
android:text="Two"
android:id="@+id/button2"
android:layout_height="70px"
android:layout_width="70px"
android:layout_weight="1">
</Button>
</LinearLayout>
जब मैं निष्पादित कोड है क्या होता है:
अपने पदों का आदान-प्रदान करने वाले बटनों के बजाय, वे कुछ समय के लिए गायब हो जाते हैं [ 500 एमएस हो सकता है] और मूल रूप से वे फिर से दिखाई देते हैं।
इस समस्या को हल करने के लिए कैसे करें? क्या यह डिवाइस में ठीक तरह से काम करेगा?
में कोड रखो प्रयास करें? –