[android-developers] How to make a custom View having it's height = width ?

2009-06-24 Thread Tonio

Hi guy,

I'm trying to make my custom view looks like a square...
I'm putting my view in a linear layout like this :

LinearLayout
- Header view
- square view (my custom view)
- footer view

With the screen orientation set to "Portrait" *I would like my square
view to have height the same as it's width.
My custom view extends View class and override the onDraw method...

I can't figure out how to tell my view to take height=width within the
linear layout.
Is it possible using onLayout, onsizeChanged, onMeasure
And what should i do with this method

In onMeasure I guess I should tell that measuredHeight should be the
same as measureWidth wich should be equals to the linearLayout
width... but How can I be aware at this time (onMeasure) of the width
of my contentLayout (linearLayout) ?

Thx

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Problem with dialog title and dialog background

2009-06-24 Thread Tonio

Hey,

I'm facing a problem when trying to customize dialogs in my
application. Here is the description.

I have an activity louching a Dialog created as follow

protected Dialog onCreateDialog(int id) {
Dialog selectorDialog;
View layout = getLayoutInflater().inflate(R.layout.MyLayout,
(ViewGroup) findViewById(R.id.root_layout));
selectorDialog = new Dialog(this, R.style.MyLayout);
selectorDialog.addContentView(layout, new LayoutParams
(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
return selectorDialog;
}

For easy understanding MyLayout is a single line of Text (LinearLayout
+ TextView)
I use a custom theme :

@drawable/MyBackground


The result is nice, I have MyBackground image set for my
selectorDialog but...
I have a blank space that correspond to the dialog title and I don't
want it !!!
(If i set selectorDialog.setTitle("Test"); I can see "Test" written in
the undesired space...)

So I tried to set :

selectorDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

But the displayed dialog looks like the same as when I use an
AlertDialog.Builder :

protected Dialog onCreateDialog(int id) {
Dialog selectorDialog;
View layout = getLayoutInflater().inflate(R.layout.MyLayout,
(ViewGroup) findViewById(R.id.root_layout));
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(layout);
selectorDialog = builder.create();
return selectorDialog;
}

In the first case : selectorDialog.requestWindowFeature
(Window.FEATURE_NO_TITLE);
I set MyTheme when creating the Dialog instance but it doesn't seem
that it takes effect.
I have no title... but not the custom Dialog background specified in
styles.xml

In the second case I can't figure (out) how to set the theme... and I
have the same result : no title but the standard Android AlertDialog
Theme.

I prospect in the platform (1.5) /res
And i Find  in themes.xml :

 @android:style/AlertDialog

And in styles.xml :


@android:drawable/popup_full_dark
@android:drawable/popup_top_dark
@android:drawable/popup_center_dark
@android:drawable/popup_bottom_dark
@android:drawable/popup_full_bright
@android:drawable/popup_top_bright
@android:drawable/
popup_center_bright
@android:drawable/
popup_bottom_bright
@android:drawable/
popup_bottom_medium
@android:drawable/
popup_center_medium


I also tried to extend this AlerteDialog style but the attributes
fullDark, topDark, ... are not public so I can't override those
properties Moreover I dont want to override 10 properties I have a
single custom NinePathDrawable that fits perfectly for my dialog
background !!

Has one of you already manage to set a custom background for a custom
Dialog without having the useless title space displayed ?

Is there anyway to customize this by themes & styles ?

Thank you for your help.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---