Home App template and FrameLayouts from code

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Home App template and FrameLayouts from code

Postby pskink » Sun Mar 08, 2009 8:36 pm

hi,

created something that can be used as basic template for Home App.

it contains 2 x 3 virtual screens: each screen is FrameLayout created in code.

my problem is when i try to add something (see page_1_1) i cannot fill it to the whole page.

any hints?
Attachments
Home.tar.gz
(8.22 KiB) Downloaded 49 times
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Top

Postby MrSnowflake » Mon Mar 09, 2009 12:50 pm

I'm trying to figure it out, what I have found is that when you change the layout_width of one of the views inside page_1_1 to a fixed size, it does scale up as wanted.

The strange thing: the FrameLayout has a width of 320, but the linlayout inside it has only a width of 237.

Also another strange thing: when you make (for example) the TextView have layout_heigth="fill_parent" then the box doesn't change size, but the 2 buttons lay outside of the visible area of page_1_1. Strange stuff.
Last edited by MrSnowflake on Mon Mar 09, 2009 1:00 pm, edited 1 time in total.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby MrSnowflake » Mon Mar 09, 2009 1:19 pm

Ok, I think I found your mistake!

in HomeView.onLayout() you call mPages[][].measure() and specify the size in pixels, but it expects MeasureSpecs. So my sollution is to chagne you onLayout() to:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         protected void onLayout(boolean changed, int l, int t, int r, int b) {
  2.  
  3.                 Log.d(TAG, "onLayout " + r + " " + b + " count " + getChildCount());
  4.  
  5.                 for (int x = 0; x<NUM_PAGES_X; x++) {
  6.  
  7.                         for (int y = 0; y<NUM_PAGES_Y; y++) {
  8.  
  9.                                 int xx = x * mPageWidth;
  10.  
  11.                                 int yy = y * mPageHeight;
  12.  
  13.                                 //mPages[x][y].measure(mPageWidth, mPageHeight);
  14.  
  15.                                 int widthMeasureSpec = MeasureSpec.makeMeasureSpec(mPageWidth, MeasureSpec.EXACTLY);
  16.  
  17.                                 int heightMeasureSpec = MeasureSpec.makeMeasureSpec(mPageHeight, MeasureSpec.EXACTLY);
  18.  
  19.                                 mPages[x][y].measure(widthMeasureSpec, heightMeasureSpec);
  20.  
  21.                                 mPages[x][y].layout(xx, yy, xx+mPageWidth, yy+mPageHeight);
  22.  
  23.                         }
  24.  
  25.                 }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
I'm not sure if this solves the problem, but atleast the page_1_1 layout is now sized correctly.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby pskink » Mon Mar 09, 2009 3:00 pm

MrSnowflake wrote:Ok, I think I found your mistake!

in HomeView.onLayout() you call mPages[][].measure() and specify the size in pixels, but it expects MeasureSpecs.


thanx MrSnowflake, already found that i call measure with raw ints... (btw they could warn via Log.w if params are not cooked)

also fixed problem with individual page sizes

i wonder if anyone interested in making not google Home...
Attachments
Home.tar.gz
(14.01 KiB) Downloaded 49 times
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 8 guests