3 Replies - 265 Views - Last Post: 25 January 2013 - 02:30 PM

#1 mattlyons  Icon User is offline

  • D.I.C Regular

Reputation: 6
  • View blog
  • Posts: 301
  • Joined: 10-September 09

3 TableLayouts in a LinearLayout

Posted 24 January 2013 - 10:16 AM

I am attempting to place multiple TableLayouts inside of a LinearLayout. When I implemented the code and ran it, the display was my background image with nothing displayed on it. Not sure what happened.

Before I tried to do this, I had everything displaying correctly but it was so much text that it had to be extremely small to make everything fit. To fix this I want to do 3 TableLayouts with the middle one being a ScrollView (I will worry about implementing the ScrollView after I fix the problem at hand).

My question is how to make all 3 TableLayouts visible with each being a specific percentage of the screen.

Below is 100% of the code for this XML file.

    <LinearLayout
    	xmlns:android="http://schemas.android.com/apk/res/android"
       	xmlns:tools="http://schemas.android.com/tools"
       	android:id="@+id/tableLayout"
       	android:layout_width="fill_parent"
       	android:layout_height="fill_parent"
       	android:stretchColumns="1"
       	android:shrinkColumns="0"
    	android:orientation="vertical"
       	android:paddingLeft="16dp"
     	android:paddingRight="16dp"
     	android:paddingTop="70dp"
     	android:paddingBottom="70dp"
       	android:background="@drawable/scroll" >    
        
        <TableLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1" >
            	
    	    <TableRow
    	        android:id="@+id/header"
    	        android:layout_width="0dip"
    	        android:layout_height="wrap_content"
    	        android:layout_weight="1" >
    	        
    	        <TextView
    	        	android:id="@+id/category"
    	            android:layout_height="wrap_content"
    	            android:layout_width="0px"
    		        android:layout_weight="1"
    		        android:textStyle="bold"
    		        android:textSize="15sp"
    		        android:paddingTop="10dp"
    		        android:gravity="center_horizontal" />
    	        
    	        <TableLayout
    	        	android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight="1" >
    	        	
    	            <TableRow
    	                android:layout_width="0dip"
    	        		android:layout_height="wrap_content"
    	        		android:layout_weight="1" >
    	        		
    		            <TextView
    		            	android:id="@+id/points"
    			    		android:layout_width="0dip"
    		        		android:layout_height="wrap_content"
    		        		android:layout_weight=".25"
    		        		android:textSize="7sp"
    		        		android:gravity="left" 
    		        		android:textStyle="bold" />
    		        </TableRow>
    		        
    	            <TableRow
    	                android:layout_width="0dip"
    	        		android:layout_height="wrap_content"
    	        		android:layout_weight="1" >
    		            
    		        	<TextView
    		            	android:id="@+id/percentage"
    		            	android:layout_width="0dip"
    		            	android:layout_height="wrap_content"
    		            	android:layout_weight=".3"
    		            	android:textSize="7sp"
    		            	android:gravity="left"
    						android:textStyle="bold" />
    		        </TableRow>
    		        
    	            <TableRow
    	                android:layout_width="0dip"
    	        		android:layout_height="wrap_content"
    	        		android:layout_weight="1" >
    					        
    		        	<TextView
    		        	    android:id="@+id/total_score"
    		            	android:layout_width="0dip"
    		            	android:layout_height="wrap_content"
    		            	android:layout_weight=".45"
    		            	android:textSize="7sp"
    		            	android:gravity="left"
    		            	android:textStyle="bold" />
    		        </TableRow>
    	    	</TableLayout>
    	    </TableRow>
        
    	    <View 
    			android:layout_width="fill_parent"
    			android:layout_height="1dp"       
    			android:background="#000001" />
    	
    	    <TableRow
    	        android:id="@+id/row3"
    	        android:layout_width="0dip"
    	        android:layout_height="wrap_content"
    	        android:layout_weight="1" >
    	        
    	        <TextView
    	            android:id="@+id/imageColumn"
    	            android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight="0" />
    	        
    	        <TextView
    	            android:id="@+id/questionColumn"
    	            android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".45"
    	        	android:textSize="10sp"
    	        	android:textStyle="bold|italic"
    	        	android:gravity="center_vertical" />
    	        
    	        <TextView
    	            android:id="@+id/answerColumn"
    	            android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".3"
    	        	android:textSize="10sp"
    	        	android:textStyle="bold|italic"
    	        	android:gravity="center_vertical" />
    	        
    	        <TextView
    	            android:id="@+id/verseColumn"
    	            android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".25"
    	        	android:textSize="10sp"
    	        	android:textStyle="bold|italic"
    	        	android:gravity="center_vertical" />
    	    </TableRow>
    	</TableLayout>
                
        <TableLayout
            android:layout_width="0dip"
    	    android:layout_height="wrap_content"
    	    android:layout_weight="1" >
    		
    		<TableRow
    	       	android:layout_width="0dip"
    	       	android:layout_height="wrap_content"
    	  	    android:stretchColumns="0,1,2,3"
    	      	android:layout_weight="1" >
    	      
    		    <ImageView
    		        android:id="@+id/q1Image"
    				android:layout_width="10dp"
    				android:layout_height="10dp"
    				android:layout_gravity="center_vertical" />
    	   
    		    <TextView
    		        android:id="@+id/q1Question"
    		    	android:layout_width="0dip"
    	      		android:layout_height="wrap_content"
    	   			android:layout_weight=".45"
    	      		android:textSize="7sp"
    	      		android:paddingLeft="2dp"
    	      		android:paddingRight="2dp"
    	      		android:layout_gravity="center_vertical" />
    	   
    	  		<TextView
    	       		android:id="@+id/q1Answer"
    	   			android:layout_width="0dip"
    	      		android:layout_height="wrap_content"
    	      		android:layout_weight=".3"
    	      		android:textSize="7sp"
    	      		android:layout_gravity="center_vertical" />
    	   
    	   		<TextView
    	       		android:id="@+id/q1Verse"
    	   			android:layout_width="0dip"
    	   			android:layout_height="wrap_content"
    	   			android:layout_weight=".25"
    	   			android:textSize="7sp"
    	  	   		android:layout_gravity="center_vertical" />
    		</TableRow>
    	
    	    <View 
    			android:layout_width="fill_parent"
    			android:layout_height="1dp"       
    			android:background="#C2BEBF" />
    	
    	    <TableRow
    	        android:id="@+id/row5"
    	        android:layout_width="0dip"
    	        android:layout_height="wrap_content"
    	        android:stretchColumns="0,1,2,3"
    	        android:layout_weight="1" >
    	        
    		    <ImageView
    		        android:id="@+id/q2Image"
    				android:layout_width="10dp"
    				android:layout_height="10dp"
    				android:layout_gravity="center_vertical" />
    		    
    		    <TextView
    		        android:id="@+id/q2Question"
    		    	android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".45"
    	        	android:textSize="7sp"
    	        	android:paddingLeft="2dp"
    	        	android:paddingRight="2dp"
    	        	android:layout_gravity="center_vertical" />
    		    
    		    <TextView
    		        android:id="@+id/q2Answer"
    		    	android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".3"
    	        	android:textSize="7sp"
    	        	android:layout_gravity="center_vertical" />
    		    
    		    <TextView
    		        android:id="@+id/q2Verse"
    		    	android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".25"
    	        	android:textSize="7sp"
    	        	android:layout_gravity="center_vertical" />
    		</TableRow>
    		
    	    <View 
    			android:layout_width="fill_parent"
    			android:layout_height="1dp"       
    			android:background="#C2BEBF" />
    		
    	    <TableRow
    	        android:id="@+id/row6"
    	        android:layout_width="0dip"
    	        android:layout_height="wrap_content"
    	        android:stretchColumns="0,1,2,3"
    	        android:layout_weight="1" >
    	        
    		    <ImageView
    		        android:id="@+id/q3Image"
    				android:layout_width="10dp"
    				android:layout_height="10dp"
    				android:layout_gravity="center_vertical" />
    		    
    		    <TextView
    		        android:id="@+id/q3Question"
    		    	android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".45"
    	        	android:textSize="7sp"
    	        	android:paddingLeft="2dp"
    	        	android:paddingRight="2dp"
    	        	android:layout_gravity="center_vertical" />
    		    
    		    <TextView
    		        android:id="@+id/q3Answer"
    		    	android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".3"
    	        	android:textSize="7sp"
    	        	android:layout_gravity="center_vertical" />
    		    
    		    <TextView
    		        android:id="@+id/q3Verse"
    		    	android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".25"
    	        	android:textSize="7sp"
    	        	android:layout_gravity="center_vertical" />
    		</TableRow>
    		
    	    <View 
    			android:layout_width="fill_parent"
    			android:layout_height="1dp"       
    			android:background="#C2BEBF" />
    		
    	    <TableRow
    	        android:id="@+id/row7"
    	        android:layout_width="0dip"
    	        android:layout_height="wrap_content"
    	        android:stretchColumns="0,1,2,3"
    	        android:layout_weight="1" >
    	        
    		    <ImageView
    		        android:id="@+id/q4Image"
    				android:layout_width="10dp"
    				android:layout_height="10dp"
    				android:layout_gravity="center_vertical" />
    		    
    		    <TextView
    		        android:id="@+id/q4Question"
    		    	android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".45"
    	        	android:textSize="7sp"
    	        	android:paddingLeft="2dp"
    	        	android:paddingRight="2dp"
    	        	android:layout_gravity="center_vertical" />
    		    
    		    <TextView
    		        android:id="@+id/q4Answer"
    		    	android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".3"
    	        	android:textSize="7sp"
    	        	android:layout_gravity="center_vertical" />
    		    
    		    <TextView
    		        android:id="@+id/q4Verse"
    		    	android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".25"
    	        	android:textSize="7sp"
    	        	android:layout_gravity="center_vertical" />
    		</TableRow>
    		
    	    <View 
    			android:layout_width="fill_parent"
    			android:layout_height="1dp"       
    			android:background="#C2BEBF" />
    		
    	    <TableRow
    	        android:id="@+id/row8"
    	        android:layout_width="0dip"
    	        android:layout_height="wrap_content"
    	        android:stretchColumns="0,1,2,3"
    	        android:layout_weight="1" >
    	        
    		    <ImageView
    		        android:id="@+id/q5Image"
    				android:layout_width="10dp"
    				android:layout_height="10dp"
    				android:layout_gravity="center_vertical" />
    		    
    		    <TextView
    		        android:id="@+id/q5Question"
    		    	android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".45"
    	        	android:textSize="7sp"
    	        	android:paddingLeft="2dp"
    	        	android:paddingRight="2dp"
    	        	android:layout_gravity="center_vertical" />
    		    
    		    <TextView
    		        android:id="@+id/q5Answer"
    		    	android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".3"
    	        	android:textSize="7sp"
    	        	android:layout_gravity="center_vertical" />
    		    
    		    <TextView
    		        android:id="@+id/q5Verse"
    		    	android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".25"
    	        	android:textSize="7sp"
    	        	android:layout_gravity="center_vertical" />
    		</TableRow>
    		
    	    <View 
    			android:layout_width="fill_parent"
    			android:layout_height="1dp"       
    			android:background="#C2BEBF" />
    		
    	    <TableRow
    	        android:id="@+id/row9"
    	        android:layout_width="0dip"
    	        android:layout_height="wrap_content"
    	        android:stretchColumns="0,1,2,3"
    	        android:layout_weight="1" >
    	        
    		    <ImageView
    		        android:id="@+id/q6Image"
    				android:layout_width="10dp"
    				android:layout_height="10dp"
    				android:layout_gravity="center_vertical" />
    		    
    		    <TextView
    		        android:id="@+id/q6Question"
    		    	android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".45"
    	        	android:textSize="7sp"
    	        	android:paddingLeft="2dp"
    	        	android:paddingRight="2dp"
    	        	android:layout_gravity="center_vertical" />
    		    
    		    <TextView
    		        android:id="@+id/q6Answer"
    		    	android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".3"
    	        	android:textSize="7sp"
    	        	android:layout_gravity="center_vertical" />
    		    
    		    <TextView
    		        android:id="@+id/q6Verse"
    		    	android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".25"
    	        	android:textSize="7sp"
    	        	android:layout_gravity="center_vertical" />
    		</TableRow>
    		
    	    <View 
    			android:layout_width="fill_parent"
    			android:layout_height="1dp"       
    			android:background="#C2BEBF" />
    		
    	    <TableRow
    	        android:id="@+id/row10"
    	        android:layout_width="0dip"
    	        android:layout_height="wrap_content"
    	        android:stretchColumns="0,1,2,3"
    	        android:layout_weight="1" >
    	        
    		    <ImageView
    		        android:id="@+id/q7Image"
    				android:layout_width="10dp"
    				android:layout_height="10dp"
    				android:layout_gravity="center_vertical" />
    		    
    		    <TextView
    		        android:id="@+id/q7Question"
    		    	android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".45"
    	        	android:textSize="7sp"
    	        	android:paddingLeft="2dp"
    	        	android:paddingRight="2dp"
    	        	android:layout_gravity="center_vertical" />
    		    
    		    <TextView
    		        android:id="@+id/q7Answer"
    		    	android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".3"
    	        	android:textSize="7sp"
    	        	android:layout_gravity="center_vertical" />
    		    
    		    <TextView
    		        android:id="@+id/q7Verse"
    		    	android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".25"
    	        	android:textSize="7sp"
    	        	android:layout_gravity="center_vertical" />
    		</TableRow>
    		
    	    <View 
    			android:layout_width="fill_parent"
    			android:layout_height="1dp"       
    			android:background="#C2BEBF" />
    		
    	    <TableRow
    	        android:id="@+id/row11"
    	        android:layout_width="0dip"
    	        android:layout_height="wrap_content"
    	        android:stretchColumns="0,1,2,3"
    	        android:layout_weight="1" >
    	        
    		    <ImageView
    		        android:id="@+id/q8Image"
    				android:layout_width="10dp"
    				android:layout_height="10dp"
    				android:layout_gravity="center_vertical" />
    		    
    		    <TextView
    		        android:id="@+id/q8Question"
    		    	android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".45"
    	        	android:textSize="7sp"
    	        	android:paddingLeft="2dp"
    	        	android:paddingRight="2dp"
    	        	android:layout_gravity="center_vertical" />
    		    
    		    <TextView
    		        android:id="@+id/q8Answer"
    		    	android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".3"
    	        	android:textSize="7sp"
    	        	android:layout_gravity="center_vertical" />
    		    
    		    <TextView
    		        android:id="@+id/q8Verse"
    		    	android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".25"
    	        	android:textSize="7sp"
    	        	android:layout_gravity="center_vertical" />
    		</TableRow>
    		
    	    <View 
    			android:layout_width="fill_parent"
    			android:layout_height="1dp"       
    			android:background="#C2BEBF" />
    		
    	    <TableRow
    	        android:id="@+id/row12"
    	        android:layout_width="0dip"
    	        android:layout_height="wrap_content"
    	        android:stretchColumns="0,1,2,3"
    	        android:layout_weight="1" >
    	        
    		    <ImageView
    		        android:id="@+id/q9Image"
    				android:layout_width="10dp"
    				android:layout_height="10dp"
    				android:layout_gravity="center_vertical" />
    		    
    		    <TextView
    		        android:id="@+id/q9Question"
    		    	android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".45"
    	        	android:textSize="7sp"
    	        	android:paddingLeft="2dp"
    	        	android:paddingRight="2dp"
    	        	android:layout_gravity="center_vertical" />
    		    
    		    <TextView
    		        android:id="@+id/q9Answer"
    		    	android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".3"
    	        	android:textSize="7sp"
    	        	android:layout_gravity="center_vertical" />
    		    
    		    <TextView
    		        android:id="@+id/q9Verse"
    		    	android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".25"
    	        	android:textSize="7sp"
    	        	android:layout_gravity="center_vertical" />
    		</TableRow>
    		
    	    <View 
    			android:layout_width="fill_parent"
    			android:layout_height="1dp"       
    			android:background="#C2BEBF" />
    		
    	    <TableRow
    	        android:id="@+id/row13"
    	        android:layout_width="0dip"
    	        android:layout_height="wrap_content"
    	        android:stretchColumns="0,1,2,3"
    	        android:layout_weight="1" >
    	        
    		    <ImageView
    		        android:id="@+id/q10Image"
    				android:layout_width="10dp"
    				android:layout_height="10dp"
    				android:layout_gravity="center_vertical" />
    		    
    		    <TextView
    		        android:id="@+id/q10Question"
    		    	android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".45"
    	        	android:textSize="7sp"
    	        	android:paddingLeft="2dp"
    	        	android:paddingRight="2dp"
    	        	android:layout_gravity="center_vertical" />
    		    
    		    <TextView
    		        android:id="@+id/q10Answer"
    		    	android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".3"
    	        	android:textSize="7sp"
    	        	android:layout_gravity="center_vertical" />
    		    
    		    <TextView
    		        android:id="@+id/q10Verse"
    		    	android:layout_width="0dip"
    	        	android:layout_height="wrap_content"
    	        	android:layout_weight=".25"
    	        	android:textSize="7sp"
    	        	android:layout_gravity="center_vertical" />
    		</TableRow>
    	</TableLayout>
            
        <TableLayout
            android:layout_width="0dip"
           	android:layout_height="wrap_content"
           	android:layout_weight="1" >
    
            <TableRow
    	        android:id="@+id/row14"
    	        android:layout_width="0dip"
    	        android:layout_height="wrap_content"
    	        android:stretchColumns="0,1"
    	        android:layout_weight="1" >
    		    
    			<Button 
    		        android:id="@+id/mainmenuBtn"
    		       	android:layout_width="0dip"
    		       	android:layout_height="wrap_content"
    		       	android:layout_weight=".33"
    		       	android:textSize="7sp" />
    		    	
    		    <Button 
    		        android:id="@+id/highscoresBtn"
    		       	android:layout_width="0dip"
    		       	android:layout_height="wrap_content"
    		       	android:layout_weight=".33"
    		       	android:textSize="7sp" />
    		    <Button 
    		        android:id="@+id/playBtn"
    		       	android:layout_width="0dip"
    		       	android:layout_height="wrap_content"
    		       	android:layout_weight=".34"
    		       	android:textSize="7sp" />
    		</TableRow>
    	</TableLayout>
    </LinearLayout>



Is This A Good Question/Topic? 1
  • +

Replies To: 3 TableLayouts in a LinearLayout

#2 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 841
  • View blog
  • Posts: 2,576
  • Joined: 29-July 11

Re: 3 TableLayouts in a LinearLayout

Posted 24 January 2013 - 06:39 PM

Hi, Matt. As far as I know, there is no resolution independent way to to make each column of a tablelayout take up a percentage of the screen. You can do stretchColumns="*" and they will all share the left over screen resolution, but that may not be what you want. I didn't take the time to deciper your code, because it is just too long, but what I did read didn't make much sense to me. Why are you nesting tablerows within a tablerow?

I have never done something in tablelayout that I could not do much easier in relativelayout. My advice is to ditch Tablelayout and go relativelayout.

You could also try gridlayout and give the left and right sides more priority than the middle as well.
Was This Post Helpful? 2
  • +
  • -

#3 mattlyons  Icon User is offline

  • D.I.C Regular

Reputation: 6
  • View blog
  • Posts: 301
  • Joined: 10-September 09

Re: 3 TableLayouts in a LinearLayout

Posted 25 January 2013 - 09:42 AM

Hey Farrell. I was not trying to make columns take up a percentage of the screen horizontally. I was trying to make a whole TableLayout take up a percentage of the screen vertically. I was basically trying to split the screen vertically into 3 sections -- two nonscrolling sections and one scrolling section.

I am pretty sure there are no TableRows nested inside of TableRows. There are TableLayouts with TableRows inside of it nested within a TableRow, but that is it.

I actually figured out how to make this work but the code is getting very messy (to me). I might need to take your advice and discover how GridLayout and RelativeLayouts work. It probably would be better than what I am doing. I just hate to stop with what I got since it is working, sort of, and I have so much written.
Was This Post Helpful? 0
  • +
  • -

#4 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 841
  • View blog
  • Posts: 2,576
  • Joined: 29-July 11

Re: 3 TableLayouts in a LinearLayout

Posted 25 January 2013 - 02:30 PM

View Postmattlyons, on 25 January 2013 - 04:42 PM, said:

I actually figured out how to make this work but the code is getting very messy (to me). I might need to take your advice and discover how GridLayout and RelativeLayouts work. It probably would be better than what I am doing. I just hate to stop with what I got since it is working, sort of, and I have so much written.


I hear you, dude. UI is can be frustrating. My bad on the TableTow within a TableRow. I see what you did :)

In a situation where you want to split the screen into 3 sizes, I'd start just use 3 linear layouts. One top and bottom taking 40%, then 20% for the middle via layout weight.

Anyway, good luck.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1