Hello, Everyone!
I have two Button-like Views that can change its size at runtime, by
setting new text to them with setText.
By that, height of one button might change and become bigger. So, I
need to resize second Button at that moment.
My objective is to make both View have the same height, that is
maximum height of them.
I am trying to Override onSizeChanged() method of this two Views:
public class MyButton extends Button {
private MyButton neighbouringButton;
//* Constructors omitted *//
public void setNeighbouringButton(MyButton neighbouringButton) {
this.neighbouringButton = neighbouringButton;
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
if (neighbouringButton != null) {
int nh = neighbouringButton.getMeasuredHeight();
if (h > oldh && h > nh)
neighbouringButton.setHeight(h);
}
super.onSizeChanged(w, h, oldw, oldh);
}
}
I update text of my buttons at least two times. This code gives very
weird effect: if any View need to change it doesn't let it become
bigger, so text becomes croped.
I use this MyButtons with xml layout, inside LinearLayout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="10px"
android:paddingBottom="10px"
>
<org.apps.MyButton
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="45"
android:gravity="center"
android:text="button1"
android:textColor="#ff0"
android:textSize="17px"
android:background="@drawable/button"/>
<org.apps.MyButton
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="45"
android:gravity="center"
android:text="button2"
android:textColor="#0f0"
android:textSize="17px"
android:background="@drawable/button"/>
Do I solve this problem by wrong means? Where am I wrong and how
should I solve this problem correctly?
Regards
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en