I believe I found a solution to your problem. The weight attribute of
linearlayouts (http://d.android.com/reference/android/widget/
LinearLayout.LayoutParams.html) unfortunately only extends views, and
therefore the your attempt does not work, because the textviews are to
wide to begin with. I found that it worked to simply set
android:width="0px", and then let the weight-attribute do its work.

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
  xmlns:android="http://schemas.android.com/apk/res/android";
  android:layout_width="fill_parent"
  android:layout_height="wrap_content" >
  <TableRow>
    <TextView
      android:text="ab ab abc abcabc ab"
      android:background="#FFFF0000"
      android:width="0px"
      android:gravity="center"
      android:layout_weight="0.5"/>
    <TextView
      android:text="ab ab abc abcabc in aaaaa aaaa aaaaaa aaaaa
aaaaaa"
      android:width="0px"
      android:background="#FF00FFFF"
      android:layout_weight="0.5"
      android:gravity="center"/>
  </TableRow>
</TableLayout>

On 14 Jan., 06:47, kknight <[email protected]> wrote:
> I want to create atablewith one row and two column. Each column is a
> TextView. I want to give50% width to each of the column, though each
> column has different length. I tried to set column width using
> layout_weight. But in the result, column 1 is much short than column
> 2. Can someone point out what is wrong, and how to force each column
> to have the same width?
>
> The XML is like below:
>
> <?xml version="1.0" encoding="utf-8"?>
> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
> android"
>         android:orientation="vertical" android:layout_width="fill_parent"
>         android:layout_height="fill_parent">
>
>         <TableLayout android:layout_width="fill_parent"
>                 android:layout_height="wrap_content"
> android:background="#ffffff">
>                 <TableRow android:weightSum="1.0">
>                         <LinearLayout android:orientation="vertical"
>                                 android:background="#ffffff"
> android:layout_column="0"
>                                 android:layout_weight="0.5">
>                                 <TextView
> android:layout_width="fill_parent"
>
> android:layout_height="wrap_content"
>                                         android:text="ab ab abc abcabc
> ab "
>                                         android:textColor="#231ACC"
> android:padding="3dip" />
>                         </LinearLayout>
>                         <LinearLayout android:orientation="vertical"
>                                 android:background="#ffffff"
> android:layout_column="1"
>                                 android:layout_weight="0.5">
>                                 <TextView
> android:layout_width="fill_parent"
>
> android:layout_height="wrap_content"
>                                         android:text="ab ab abc abcabc
> in aaaaa aaaa aaaaaa aaaaa aaaaaa"
>                                         android:textColor="#231ACC"
> android:padding="3dip" />
>                         </LinearLayout>
>                 </TableRow>
>         </TableLayout>
>
> </LinearLayout>
>
> The results is like:
>
> Column1:
> ab ab
> abc
> abcabc
> ab
>
> Column 2:
> ab ab abc abcabc in aaaaa aaaa aaaaaa
> aaaaa aaaaaa

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to