I have a custom style RadioButton suite. I want to display a frame around the button that is currently being tested. This should be fairly straightforward using XML, but now I want the border to be animated. If a new switch is set, the border should "fly" to a new location using fantastic animation:
+------+ |* btn1| o btn2 +------+ +------+ ob|n1 * |tn2 +------+ +------+ o btn1 |* btn2| +------+
Because of this, I decided to turn the border into a separate View object so that I can animate it properly. The problem is tracking the location of the corresponding switch on the screen.
I am trying to make it work without animation. My current attempt looks something like this (only with the corresponding attributes):
<RelativeLayout android:layout_alignParentLeft="true" android:layout_alignParentTop="true"> <RadioGroup android:id="@+id/radio_group"> <RadioButton/> <RadioButton/> <RadioButton/> </RadioGroup> <View android:id="@+id/selection_border" android:layout_alignParentLeft="true" android:layout_alignParentTop="true"/> </RelativeLayout>
In OnCheckedChangeListener RadioGroup , I move the selection frame by setting its field (I could set the position, but a little more complicated with RelativeLayout ):
View radioButton = findViewById(checkedId); View selectionBorder = findViewById(R.id.selection_border); ViewGroup radioGroup = (ViewGroup)findViewById(R.id.radio_group); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(selectionBorder.getLayoutParams()); params.leftMargin = radioGroup.getLeft() + radioButton.getLeft(); params.topMargin = radioGroup.getTop() + radioButton.getTop(); selection.setLayoutParams(params); selection.requestLayout();
However, a problem occurs during initialization. Since the layout has not yet been completed, the position of the border is set incorrectly. It seems that it is impossible to immediately turn off the relay, and it is not possible to receive the event after the layout has been completed.
All these troubles make me think that there should be a cleaner way to achieve what I want. Any bright ideas?
android android-layout
Thomas
source share