Mark,

thanks for your quick reply.

Actually I try to create a custom background with
-> alternate colors (even and odd)
-> rounded rectangle shaped

I try to extend RadioButton directly but the result was not what I
expected (the text and button was kind of "greyed" or set with a high
transparency ...)

I think there is maybe a solution with a shape definition in XML files
but I can't find any documentation.

I can even provide you the code of the view I inflate and the XML
layout linked:
package com.xirgonium.android.view;

import java.util.Map;

import com.xirgonium.android.R;
import com.grvs.android.util.Constant;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Paint.Style;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.RadioButton;

public class RadioButtonBackgrounded extends LinearLayout {

    private Paint innerPaint, borderPaint;
    private int   colorsTheme = 0;

    public RadioButtonBackgrounded(Context context){
        super(context);
        init();
    }
    public RadioButtonBackgrounded(Context context, AttributeSet
attrs, Map inflateParams){
        super(context, attrs, inflateParams);
        init();
    }

    private void init() {
        innerPaint = new Paint();
        innerPaint.setAntiAlias(true);

        borderPaint = new Paint();
        borderPaint.setAntiAlias(true);
        borderPaint.setStyle(Style.STROKE);
        borderPaint.setStrokeWidth(1);
    }

    void setColors(){
 
borderPaint.setColor(getResources().getColor(R.color.item_border));

        switch (colorsTheme) {
            case Constant.COLOR_THEME_ITEM_ODD:
 
innerPaint.setColor(getResources().getColor(R.color.item_odd_background));
                break;
            case Constant.COLOR_THEME_ITEM_EVEN:
 
innerPaint.setColor(getResources().getColor(R.color.item_even_background));
                break;
            default:
                break;
        }
    }

    public void setInnerPaint(Paint innerPaint) {
        this.innerPaint = innerPaint;
    }

    public void setBorderPaint(Paint borderPaint) {
        this.borderPaint = borderPaint;
    }

    protected void dispatchDraw(Canvas canvas) {

        setColors();

        RectF drawRect = new RectF();
        drawRect.set(1, 1, getMeasuredWidth()-2, getMeasuredHeight() -
2);
        canvas.drawRoundRect(drawRect, 5, 5, innerPaint);
        canvas.drawRoundRect(drawRect, 5, 5, borderPaint);



        super.dispatchDraw(canvas);
    }

    protected void onDraw(Canvas canvas) {

        setColors();

        RectF drawRect = new RectF();
        drawRect.set(1, 1, getMeasuredWidth() - 2, getMeasuredHeight()
- 2);

        canvas.drawRoundRect(drawRect, 5, 5, innerPaint);
        canvas.drawRoundRect(drawRect, 5, 5, borderPaint);

        super.onDraw(canvas);
    }

    public int getColorsTheme() {
        return colorsTheme;
    }

    public void setColorsTheme(int colorsTheme) {
        this.colorsTheme = colorsTheme;
    }
}

-----
XML layout
----

<?xml version="1.0" encoding="UTF-8"?>
<com.grvs.android.view.RadioButtonBackgrounded
    xmlns:android="http://schemas.android.com/apk/res/android";
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
>
    <RadioButton
        android:id="@+id/new_s2_radio_button"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:checked="false"
    />
</com.grvs.android.view.RadioButtonBackgrounded>

------
The radiogroup where I add dynamically the radiobutton

On Apr 30, 2:08 pm, Mark Murphy <[EMAIL PROTECTED]> wrote:
> 6real wrote:
> > here is what I would like to have as structure (for personnal "look
> > and feel" reasons) :
>
> > Radiogroup
> >     `- LinearLayout
> >            `-RadioButton1
> >     `- LinearLayout
> >            `-RadioButton2
> >     `- LinearLayout
> >            `-RadioButton3
>
> > So I can build it but the point is that the radiogroup is not working
> > fine. It is like if I have no radio group.
> > If I remove the LinearLayout layer, all is working fine.
>
> > Do you have any idea on how to solve this issue and to give back the
> > correct behavior to my radiogroup?
>
> Perhaps we can help you figure out a way to keep the look and feel you
> want without the intermediate LinearLayouts. Could you explain what the
> look is you're trying to achieve?
>
> --
> Mark Murphy (a Commons Guy)http://commonsware.com
> The Busy Coder's Guide to Android Development -- coming in June 2008!
--~--~---------~--~----~------------~-------~--~----~
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]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to