TableLayout issue

by rael_yoni » Sat, 26 Feb 2011 22:11:33 GMT


Sponsored Links
 I'm wrestling with the Android UI to try to create a table layout that has 2 
rows each row containing 2 ImageSwitchers, And would like the table 
to occupies the entire screen. But I simply can not accomplish it, sometimes 
the emulator shows 1 ImageSwitcher that is aligned to the right of the 
screen to its entire height, sometimes it shows nothing, sometimes the image 
aligned to the bottom of the screen (but only 1 of it)...  

I'm attaching one of the configurations I tested. It is wrong for sure but I 
really don't know what to do. any ideas are welcome... thanks.

<TableLayout android:id="@+id/TableLayout01" 
android:layout_width="fill_parent" android:layout_height="fill_parent" 
xmlns:android=" http://schemas.android.com/apk/res/android" ;>
<TableRow android:id="@+id/TableRow01" android:layout_width="wrap_content" 
android:layout_height="wrap_content">
<ImageSwitcher android:layout_column="0" 
android:id="@+id/imsLeftTop"></ImageSwitcher>  
<ImageSwitcher android:layout_column="1" 
android:id="@+id/imsRightTop"></ImageSwitcher>
</TableRow>
<TableRow android:id="@+id/TableRow02" android:layout_width="wrap_content" 
android:layout_height="wrap_content">
<ImageSwitcher android:layout_column="0" android:id="@+id/imsLeftBottom" 
<ImageSwitcher android:layout_column="1" android:id="@+id/imsRightBottom" 
</TableRow>

</TableLayout>     

-- 



Re: TableLayout issue

by TreKing » Sun, 27 Feb 2011 09:52:16 GMT


 




Ideas: Give you rows width=fill_parent. Give each of your ImageSwitchers
weight=1.
Theoretically this would make your rows fill the width of the screen and the
switcher each take up equal space within them.

-------------------------------------------------------------------------------------------------
TreKing < http://sites.google.com/site/rezmobileapps/treking> ; - Chicago
transit tracking app for Android-powered devices

-- 


Sponsored Links


Re: TableLayout issue

by rael_yoni » Mon, 28 Feb 2011 03:32:21 GMT


 First of all I would like to thank you. 

However it still not good. it shows only the first row in the middle of the 
screen (there are black "bars" above it and underneath it). and the second 
row is not seen at all... no matter what the content is (I placed TextViews 
instead of the ImageSwitcher) 

the current state of the XML is:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout android:id="@+id/TableLayout01" 
android:layout_width="fill_parent" android:layout_height="fill_parent" 
 xmlns:android=" http://schemas.android.com/apk/res/android" ;>
<TableRow android:id="@+id/TableRow01" android:layout_width="fill_parent" 
android:layout_height="fill_parent">
<ImageSwitcher android:layout_weight="1"  android:layout_column="0" 
android:id="@+id/imsLeftTop"></ImageSwitcher>  
<ImageSwitcher android:layout_weight="1" android:layout_column="1" 
android:id="@+id/imsRightTop"></ImageSwitcher>
</TableRow>
<TableRow android:id="@+id/TableRow02" android:layout_width="fill_parent" 
android:layout_height="fill_parent">
<ImageSwitcher android:layout_weight="1" android:layout_column="0" 
android:id="@+id/imsLeftBottom" ></ImageSwitcher>
<ImageSwitcher android:layout_weight="1" android:layout_column="1" 
android:id="@+id/imsRightBottom" ></ImageSwitcher>  
</TableRow>

</TableLayout>


-- 



Re: TableLayout issue

by TreKing » Mon, 28 Feb 2011 03:49:32 GMT


 




Your row heights are set to fill parent. Thus, they will both try to fill
their parent. Only one will succeed, usually the first.

-------------------------------------------------------------------------------------------------
TreKing < http://sites.google.com/site/rezmobileapps/treking> ; - Chicago
transit tracking app for Android-powered devices

-- 



Re: TableLayout issue

by rael_yoni » Mon, 28 Feb 2011 05:49:11 GMT


 That was just another test... that didn't work. 

Currently the only thing that does work is setting explicitly in code the 
height and the width of item

activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
is.setLayoutParams(new TableRow.LayoutParams(metrics.widthPixels / 2, 
metrics.heightPixels / 2));

(and even in that case the ImageSwitchers don't feel the entire of the 
screen (there is this spacing between the images and the "cell" borders).

I was hoping there is an elegant solution in code but it seems there isn't 
one. 

Thanks again. 
Yoni 

-- 



Re: TableLayout issue

by TreKing » Mon, 28 Feb 2011 06:01:52 GMT


 




Well, do you really a TableLayout in this case? If you just have two rows,
consider a LinearLayout which might work better.

-------------------------------------------------------------------------------------------------
TreKing < http://sites.google.com/site/rezmobileapps/treking> ; - Chicago
transit tracking app for Android-powered devices

-- 



Re: TableLayout issue

by Jonathan Foley » Mon, 28 Feb 2011 07:59:26 GMT


 I agree with TreKing. I have never found a situation where I actually
need a TableLayout. They are too restrictive IMO and don't afford
much control over layout. One gets better control using RelativeLayout
or LinearLayout. For the type of weighted proportional layout you're
after, you'll want to use a LinearLayout. It's the only ViewGroup that
observes the layout_weight property.  I'd use something like this
skeleton below. This will give you proportional heights of the two
rows and the ImageSwitchers will be laid out proportionally to take up
half the width of each row.  This is off the cuff so do check for
sanity!

<LinearLayout android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
 <LinearLayout android:layout_weight="1"
android:orientation="horizontal" android:layout_height="fill_parent"
android:layout_width="fill_parent">

 <ImageSwitcher android:layout_height="fill_parent"
android:layout_weight="1" android:layout_width="fill_parent" />
<ImageSwitcher android:layout_height="fill_parent"
android:layout_weight="1" android:layout_width="fill_parent" />
</LinearLayout>

 <LinearLayout android:layout_weight="1"
android:orientation="horizontal" android:layout_height="fill_parent"
android:layout_width="fill_parent">
 <ImageSwitcher android:layout_height="fill_parent"
android:layout_weight="1" android:layout_width="fill_parent" />
<ImageSwitcher android:layout_height="fill_parent"
android:layout_weight="1" android:layout_width="fill_parent" />
</LinearLayout>

</LinearLayout>


Jonathan











-- 



Re: TableLayout issue

by Zsolt Vasvari » Mon, 28 Feb 2011 10:26:02 GMT


 I agree that a TableLayout can always be replaced with Relative and/or
Linear layouts, but I still find it a very convinient shorthand in a
lot of cases.  It's also a lot more readable than a RelativeLayout and
it's also much easier to modify than the nightmare that a
RelativeLayout is when are trying to move rows/columns around.

I understand and appreciate that the RelativeLayout is usually the
most efficient memory and computation-wise, but it sure is difficult
to work with and buggy in some older versions of Android.  Another
reason I will be dropping 1.5 support soon.










-- 



Re: TableLayout issue

by rael_yoni » Mon, 28 Feb 2011 15:14:32 GMT


 Of-course I can use LinearLayout, but I wanted to understand what the 
problem was. 

Also my understanding is that TableRow is a LinearLayout so I was hoping it 
will present the same kind of behavior 
 http://developer.android.com/reference/android/widget/TableRow.html. Also  
when I initially started to work with TableLayout I was under the impression 
that it as easy as HTML Tables.... I was so wrong :-) 

Thanks.

-- 



Re: Re: TableLayout issue

by shaun walsh » Thu, 03 Mar 2011 04:27:54 GMT


 Agreed, don't use the tablelayout, the linearlayout would work much better.




rows,
---------------------------------------------------------------------------
----------------------

-- 



Other Threads

1. aplikasi Locale kok ga ada di market ku yah??

halo agan2 sekalian..

dari dulu penasaran melulu kok aplikasi yg jadi plugin nya
locale..katanya bisa didapat di market..tapi aku cari2 kok ga ada
yah???

ada yg bisa bantu??

thanks,
Joni

-- 
"Indonesian Android Community [id-android]" 

2. Upgrading android 1.1 platform to android 1.5

How are you all?

I have android phone with platform version 1.1. I have developed and
tested some applications on it, But now I want to upgrade the platform
from 1.1 to 1.5 or latest. my question is :

   1. Is it possible to upgrade the phone from 1.1 to 1.5 (or latest)
   2. If it is possible, how can I do the upgrade?

Please help me.


Thanks in advance


Andu

-- 

3. Nexus 1 opengl driver problem

4. the removal of android drivers from the staging tree

5. Working MSM7201 usb host driver v

6. paid app error

7. SMS Delivery Messag