Kostya's answer is probably what you need if you need an almost pixel- perfect division of 3:1. Implement the onMeasure method in your custom view.
On Jan 24, 9:22 am, Brill Pappin <br...@pappin.ca> wrote: > I'm afraid I don't understand the weight values. > > one of the points of a fixed height is that I'm drawing on the canvas > for the view and it has to be as exact as i can get it so that i don't > get empty space. > > There is another view below it that will align to its bottom and > should stretch to fill any left over space (via RelativeLayout). > > - Brill Pappin > > On Jan 24, 3:21 am, Dianne Hackborn <hack...@android.com> wrote: > > > > > Or you can put it in a LinearLayout and use android:layout_width="0px" > > android:layout_weight="3" with another view in the container given > > android:layout_weight="1". > > > On Sun, Jan 23, 2011 at 11:37 PM, Kostya Vasilyev <kmans...@gmail.com>wrote: > > > > Brill, > > > > Views specify their preferred size by overriding onMeasure. > > > > You've got to deal with special values representing wrap_content and > > > fill_parent (that's the MeasureSpec stuff): > > > > Here is an example, it's a view that's placed inside a ScrollView and > > > makes > > > itself "tall", even in landscape orientation: > > > > @Override > > > protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) > > > { > > > if (heightMeasureSpec != 0) { > > > int sizeWidth = MeasureSpec.getSize(widthMeasureSpec); > > > int sizeHeight = MeasureSpec.getSize(heightMeasureSpec); > > > > if (sizeHeight < sizeWidth) { > > > sizeHeight = sizeWidth * 3 / 2; > > > > heightMeasureSpec = > > > MeasureSpec.makeMeasureSpec(MeasureSpec > > > .getMode(heightMeasureSpec), sizeHeight); > > > } > > > } > > > > super.onMeasure(widthMeasureSpec, heightMeasureSpec); > > > } > > > > -- Kostya > > > > 24.01.2011 7:45, Brill Pappin пишет: > > > > Ok, I'm working on a custom view and having trouble with setting its size > > > so it scales properly across devices. > > > > In particular i want its fixed height to be relative to its width (of > > > match_parent). > > > > Something like this sudo code: > > > > View myview = new View(..); > > > > myview.setLayoutParams(new LayoutParams( > > > > LayoutParams.MATCH_PARENT, ( MATCH_PARENT / 4) * 3)); > > > > The goal would be to make the component height be 3/4's of the width. > > > > This doesn't have to be done from outside. i.e. it could be done from > > > inside the view, but I'm unsure what I need to override inside my > > > view implementation to set the height. Set it too early and i may not yet > > > have my width, set it to late and I may just end up on a resize race loop > > > :) > > > > So, my question is, what is the proper way to make a > > > View dynamically sized at runtime in at least one of the dimensions? > > > > - Brill Pappin > > > > -- > > > 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 > > > > -- > > > Kostya Vasilyev -- WiFi Manager + pretty widget > > > --http://kmansoft.wordpress.com > > > > -- > > > 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<android-developers%2Bunsubs > > > cr...@googlegroups.com> > > > For more options, visit this group at > > >http://groups.google.com/group/android-developers?hl=en > > > -- > > Dianne Hackborn > > Android framework engineer > > hack...@android.com > > > Note: please don't send private questions to me, as I don't have time to > > provide private support, and so won't reply to such e-mails. All such > > questions should be posted on public forums, where I and others can see and > > answer them.- Hide quoted text - > > - Show quoted text - -- 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