hello,

I need my own RadioButton with a complex custom design (which is not
possible using nine-patch only).

So I tought about extending RadioButton and using all features from
RadioGroup.

For the complex custom design I inflate a LinearLayout (at first I
used RelativeLayout but it seems to throw a NullPointerException, so I
tried LinearLayout which works instead).

Well, I've got some issues measuring, layouting and drawing the
LinearLayout.

Let's assume there is this complex custom design:


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android" android:layout_width="100dip"
        android:layout_height="wrap_content" android:orientation="vertical"
android:layout_weight="1"... >

        <TextView android:id="@+id/tab_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"... />

        <TextView android:id="@+id/tab_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"... />

</LinearLayout>


And this is "new" view:

public class RadioView2 extends RadioButton {

    private LinearLayout container;
    private TextView count, text;

    public RadioView2(Context context) {
        super(context);
        init(context);
    }

    public RadioView2(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public RadioView2(Context context, AttributeSet attrs, int
defStyle) {
        super(context, attrs, defStyle);
        init(context);
    }

    private void init(final Context context) {
        LayoutInflater inflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        container = (LinearLayout) inflater.inflate(R.layout.ve_radio,
null);
        count = (TextView) container.findViewById(R.id.tab_count);
        text = (TextView) container.findViewById(R.id.tab_text);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int
heightMeasureSpec) {
        container.measure(widthMeasureSpec, heightMeasureSpec);

        // here comes the problem
        setMeasuredDimension(200, 200);
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int
right, int bottom) {
        container.layout(left, top, right, bottom);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        container.draw(canvas);
    }

}

Actually I don't know how to calculate the measured dimension. To be
honest I want the RadioGroup to calculate enough space for me and I
want to delegate this space to the inflated LinearLayout.

Thank you for helping me out on this.

Best Regards,
Marco

-- 
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

Reply via email to