Need help Optimizing my Layout

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

Need help Optimizing my Layout

Postby Legend » Tue Sep 29, 2009 1:12 am

Hi,

I never designed UIs before so I apologize if the question is stupid. I am designing a UI to look something like the following:

Code: Select all
-----------------------------
ImageView          Button
-----------------------------
TabHost
0                 1              2
------------------------------
-----INSIDE EACH TAB-----
-------------------------------
TextView
ListView
    - Consists of ImageView   TextView
--------------------------------



The problem is I think I am following a very inefficient way of doing the whole stuff. The onCreate method is as follows:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void onCreate(Bundle savedInstanceState) {
  2.                 super.onCreate(savedInstanceState);
  3.                 setContentView(R.layout.main);
  4.  
  5.                 TabHost mTabHost = getTabHost();
  6.  
  7.                 Drawable Tab1Icon = getResources().getDrawable(R.drawable.tab1_icon);
  8.                 Drawable Tab2Icon = getResources().getDrawable(R.drawable.tab2_icon);
  9.                 Drawable Tab3Icon = getResources().getDrawable(R.drawable.tab3_icon);
  10.                
  11.                 mTabHost.addTab(mTabHost.newTabSpec("Tab1").setIndicator("Tab 1", Tab1Icon).setContent(new Intent(this, Tab1.class)));
  12.                 mTabHost.addTab(mTabHost.newTabSpec("Tab2").setIndicator("Tab 2", Tab1Icon).setContent(new Intent(this, Tab2.class)));
  13.                 mTabHost.addTab(mTabHost.newTabSpec("Tab3").setIndicator("Tab 3", Tab1Icon).setContent(new Intent(this, Tab3.class)));
  14.  
  15.                 mTabHost.setCurrentTab(0);
  16.         }
  17.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


This program crashes on CupCake (v1.5) complaining about StackOverflowException but runs well on Donut (v1.6). This is my main.xml:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.    android:orientation="vertical"
  4.    android:layout_width="fill_parent"
  5.    android:layout_height="fill_parent"
  6.    android:background="@color/application_background"
  7.    >
  8.    
  9.     <TableLayout
  10.                         android:id="@+id/TableLayout01"
  11.                         android:layout_width="fill_parent"
  12.                         android:layout_height="fill_parent"
  13.                         android:stretchColumns="0"
  14.                         android:background="@color/application_background">
  15.                        
  16.                 <TableRow>
  17.                         <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  18.                     android:orientation="horizontal"
  19.                     android:layout_width="fill_parent"
  20.                     android:layout_height="fill_parent">
  21.                         <ImageView id="@+id/picview1"
  22.                            android:layout_width="wrap_content"
  23.                            android:layout_height="wrap_content"
  24.                            android:src="@drawable/leftlogo"
  25.                            android:paddingRight="105sp"
  26.                          />
  27.                          <Button
  28.                                 android:id="@+id/picview2"
  29.                             android:layout_width="wrap_content"
  30.                             android:layout_height="wrap_content"
  31.                             android:background="@drawable/rightlogo"
  32.                             />
  33.                 </LinearLayout>
  34.                 </TableRow>
  35.                
  36.                 <TableRow>
  37.                         <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
  38.                             android:id="@android:id/tabhost"
  39.                             android:layout_width="fill_parent"
  40.                             android:layout_height="fill_parent">
  41.                             <LinearLayout
  42.                                 android:orientation="vertical"
  43.                                 android:layout_width="fill_parent"
  44.                                 android:layout_height="fill_parent">
  45.                                 <TabWidget
  46.                                     android:id="@android:id/tabs"
  47.                                     android:layout_width="fill_parent"
  48.                                     android:layout_height="wrap_content" />
  49.                                 <FrameLayout
  50.                                     android:id="@android:id/tabcontent"
  51.                                     android:layout_width="fill_parent"
  52.                                     android:layout_height="fill_parent">
  53.                                    
  54.                                 </FrameLayout>
  55.                             </LinearLayout>
  56.                         </TabHost>
  57.                 </TableRow>
  58.                
  59.         </TableLayout>
  60. </LinearLayout>
  61.  
  62.  
Parsed in 0.007 seconds, using GeSHi 1.0.8.4


Any suggestions regarding the design please?

Thanks
Last edited by Legend on Tue Oct 06, 2009 9:37 pm, edited 1 time in total.
Legend
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Sep 29, 2009 1:04 am

Top

Postby Legend » Sun Oct 04, 2009 10:55 pm

Anyone please?
Legend
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Sep 29, 2009 1:04 am

Postby konic » Mon Oct 05, 2009 4:17 am

Not clear, what did you use TableLayout for?
For first two ImageViews you could use just horizontal LinearLayout.
And for ListView, I think, you'd better have separate layout.
And XML contains Button, which is not in the 'picture'.
konic
Developer
Developer
 
Posts: 32
Joined: Mon Aug 24, 2009 3:16 pm

Postby Legend » Tue Oct 06, 2009 9:36 pm

Not clear, what did you use TableLayout for?
For first two ImageViews you could use just horizontal LinearLayout.
And for ListView, I think, you'd better have separate layout.


Thanks. I will change them. The HTML devil inside me made me use it I guess :) So, you mean create a separate layout for ListView and then give the XML to the TabView in code? Do you mind elaborating this a little bit?

And XML contains Button, which is not in the 'picture'.


Oops... That should've been a button instead of an ImageView...! Changed it! Thanks...
Legend
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Sep 29, 2009 1:04 am

Postby konic » Wed Oct 07, 2009 12:19 pm

I think, you can get rid of TableLayout (and TableRows),
horizontal LinearLayout for Image and Button is enough.
Don't thing you need to frame TabHost in TableRow as well.
Don't understand why did you put LinearLayout right after TabHost?
So, here is what left in the end:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.    android:orientation="vertical"
  7.  
  8.    android:layout_width="fill_parent"
  9.  
  10.    android:layout_height="fill_parent"
  11.  
  12.    android:background="@color/application_background"
  13.  
  14.    >
  15.  
  16.     <LinearLayout
  17.  
  18.        android:orientation="horizontal"
  19.  
  20.        android:layout_width="fill_parent"
  21.  
  22.        android:layout_height="wrap_content">
  23.  
  24.         <ImageView id="@+id/picview1"
  25.  
  26.            android:layout_width="wrap_content"
  27.  
  28.            android:layout_height="wrap_content"
  29.  
  30.            android:src="@drawable/leftlogo"
  31.  
  32.            android:paddingRight="105sp"
  33.  
  34.            />
  35.  
  36.         <Button
  37.  
  38.            android:id="@+id/picview2"
  39.  
  40.            android:layout_width="wrap_content"
  41.  
  42.            android:layout_height="wrap_content"
  43.  
  44.            android:background="@drawable/rightlogo"
  45.  
  46.            />
  47.  
  48.     </LinearLayout>
  49.  
  50.  
  51.  
  52.     <TabHost
  53.  
  54.        android:id="@android:id/tabhost"
  55.  
  56.        android:layout_width="fill_parent"
  57.  
  58.        android:layout_height="fill_parent">
  59.  
  60.         <TabWidget
  61.  
  62.            android:id="@android:id/tabs"
  63.  
  64.            android:layout_width="fill_parent"
  65.  
  66.            android:layout_height="wrap_content" />
  67.  
  68.         <FrameLayout
  69.  
  70.            android:id="@android:id/tabcontent"
  71.  
  72.            android:layout_width="fill_parent"
  73.  
  74.            android:layout_height="fill_parent">                            
  75.  
  76.         </FrameLayout>
  77.  
  78.     </TabHost>
  79.  
  80. </LinearLayout>
  81.  
  82.  
Parsed in 0.005 seconds, using GeSHi 1.0.8.4
konic
Developer
Developer
 
Posts: 32
Joined: Mon Aug 24, 2009 3:16 pm

Postby konic » Fri Oct 09, 2009 5:06 pm

OK,
there could be done some 'minor' tweak, - put LinearLayout inside TabHost:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.     <TabHost
  2.        android:id="@android:id/tabhost"
  3.        android:layout_width="fill_parent"
  4.        android:layout_height="fill_parent">
  5.         <LinearLayout
  6.            android:orientation="vertical"
  7.            android:layout_width="fill_parent"
  8.            android:layout_height="fill_parent">
  9.             <TabWidget
  10.                android:id="@android:id/tabs"
  11.                android:layout_width="fill_parent"
  12.                android:layout_height="wrap_content" />
  13.             <FrameLayout
  14.                android:id="@android:id/tabcontent"
  15.                android:layout_width="fill_parent"
  16.                android:layout_height="fill_parent">                            
  17.             </FrameLayout>
  18.         </LinearLayout>
  19.     </TabHost>
  20.  
Parsed in 0.003 seconds, using GeSHi 1.0.8.4

otherwise TabWidget will reside inside FrameLayout !?
konic
Developer
Developer
 
Posts: 32
Joined: Mon Aug 24, 2009 3:16 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests