Ellipsize not working for textview inside table row - android

I am using Table layout. I have two(columns) text-views in table row. I want to apply android:ellipsize="end" at the end of the textView.
But it is not working for me, see the screen shot below. Please give me any idea, how to apply ellipsize to the textview inside a table row.
Here is the code :
<TableLayout
android:id="#+id/linerLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="10dip"
android:background="#drawable/shape1"
android:stretchColumns="2" >
<TableRow
android:id="#+id/TableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Product used for "
android:textColor="#color/black_color" />
<TextView
android:id="#+id/productusedfor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:minLines="1"
android:padding="5dp"
android:singleLine="true"
android:text="TextView"
android:textColor="#color/black_color" />
</TableRow>
<TableRow
android:id="#+id/TableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Treatment for "
android:textColor="#color/black_color" />
<TextView
android:id="#+id/treatementfor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:minLines="1"
android:padding="5dp"
android:singleLine="true"
android:text="TextView"
android:textColor="#color/black_color" />
</TableRow>
<TableRow
android:id="#+id/TableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Horse Name "
android:textColor="#color/black_color" />
<TextView
android:id="#+id/horsename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="10dp"
android:ellipsize="end"
android:minLines="1"
android:padding="5dp"
android:singleLine="true"
android:text="TextView"
android:textColor="#color/black_color" />
</TableRow>
<TableRow
android:id="#+id/TableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Where "
android:textColor="#color/black_color" />
<TextView
android:id="#+id/location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:minLines="1"
android:padding="5dp"
android:singleLine="true"
android:text="TextView"
android:textColor="#color/black_color" />
</TableRow>

Try this
You have to use following property. Because textview width is wrap_content so it is going outside from the tablerow. So if you use this property then it will work: android:layout_weight="1".
<TableLayout
android:id="#+id/linerLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="10dip"
android:background="#drawable/shape1"
android:stretchColumns="2" >
<TableRow
android:id="#+id/TableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Product used for "
android:textColor="#color/black_color" />
<TextView
android:id="#+id/productusedfor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:minLines="1"
android:layout_weight="1"
android:padding="5dp"
android:singleLine="true"
android:text="fjdsngfksngfkfngkaklmngkldfmnkldgfnskldngkldnsklnghdnklgfnkdtgfndkgfn"
android:textColor="#color/black_color" />
</TableRow>
<TableRow
android:id="#+id/TableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Treatment for "
android:textColor="#color/black_color" />
<TextView
android:id="#+id/treatementfor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:minLines="1"
android:layout_weight="1"
android:padding="5dp"
android:singleLine="true"
android:text="TextView"
android:textColor="#color/black_color" />
</TableRow>
<TableRow
android:id="#+id/TableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Horse Name "
android:textColor="#color/black_color" />
<TextView
android:id="#+id/horsename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="10dp"
android:ellipsize="end"
android:minLines="1"
android:layout_weight="1"
android:padding="5dp"
android:singleLine="true"
android:text="TextView"
android:textColor="#color/black_color" />
</TableRow>
<TableRow
android:id="#+id/TableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Where "
android:textColor="#color/black_color" />
<TextView
android:id="#+id/location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:minLines="1"
android:layout_weight="1"
android:padding="5dp"
android:singleLine="true"
android:text="TextView"
android:textColor="#color/black_color" />
</TableRow>
</TableLayout>
It may work for you.

//try this
        android:maxEms="9" this attributes will do change you maxEms according to your length what you want to achive.
<TextView
android:id="#+id/productusedfor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:minLines="1"
android:padding="5dp"
android:maxEms="5"
android:singleLine="true"
android:text="TextView"
android:textColor="#color/black_color" />

For a multiline TextViews I use android:maxLines="3" in every TextView that needs ellipsize.

Related

textview on Android cut off

I have this layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout1"
style="#style/Fondo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:shape="rectangle" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:contentDescription="#string/descripcion"
android:scaleType="center"
android:src="#drawable/proyecto_logo1_aux" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/edittext_rounded_corners"
android:weightSum="19.0" >
<TableRow
android:id="#+id/TableRow05"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:background="#drawable/edittext_rounded_corners" >
<TextView
android:id="#+id/levadura_data_Nombre"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#311b10"
android:textSize="20sp"
android:textStyle="bold" />
</TableRow>
<TableRow
android:id="#+id/TableRow04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/levadura_lab"
android:textColor="#311b10" />
<TextView
android:id="#+id/levadura_data_lab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#311b10" />
</TableRow>
<TableRow
android:id="#+id/TableRow03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/levadura_productid"
android:textColor="#311b10" />
<TextView
android:id="#+id/levadura_data_idproduct"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#311b10" />
</TableRow>
<TableRow
android:id="#+id/TableRow02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0" >
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/levadura_tipo"
android:textColor="#311b10" />
<TextView
android:id="#+id/levadura_data_tipo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#311b10" />
</TableRow>
<TableRow
android:id="#+id/TableRow01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0" >
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/levadura_forma"
android:textColor="#311b10" />
<TextView
android:id="#+id/levadura_data_forma"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#311b10" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0" >
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/levadura_floculacion"
android:textColor="#311b10" />
<TextView
android:id="#+id/levadura_data_floculacion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#311b10" />
</TableRow>
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0" >
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/levadura_celulas"
android:textColor="#311b10" />
<TextView
android:id="#+id/levadura_data_celulas"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#311b10" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0" >
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/levadura_aten_min"
android:textColor="#311b10" />
<TextView
android:id="#+id/levadura_data_aten_min"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#311b10" />
</TableRow>
<TableRow
android:id="#+id/TableRow06"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0" >
<TextView
android:id="#+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/levadura_aten_max"
android:textColor="#311b10" />
<TextView
android:id="#+id/levadura_data_aten_max"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#311b10" />
</TableRow>
<TableRow
android:id="#+id/TableRow07"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0" >
<TextView
android:id="#+id/TextView04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/levadura_temp_min"
android:textColor="#311b10" />
<TextView
android:id="#+id/levadura_data_temp_min"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#311b10" />
</TableRow>
<TableRow
android:id="#+id/TableRow08"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0" >
<TextView
android:id="#+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/levadura_temp_max"
android:textColor="#311b10" />
<TextView
android:id="#+id/levadura_data_temp_max"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#311b10" />
</TableRow>
<TableRow
android:id="#+id/TableRow09"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="8.0" >
<TextView
android:id="#+id/TextView07"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/levadura_mejor"
android:textColor="#311b10" />
<TextView
android:id="#+id/levadura_data_mejor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:textColor="#311b10" />
</TableRow>
</TableLayout>
<TableLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="5dp"
android:background="#drawable/edittext_rounded_corners"
android:weightSum="1.0" >
<TableRow
android:id="#+id/TableRow11"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.1" >
<TextView
android:id="#+id/TextView05"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/levadura_notas"
android:textColor="#311b10"
android:textSize="15sp"
android:textStyle="bold" />
</TableRow>
<TableRow
android:id="#+id/TableRow17"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.9" >
<TextView
android:id="#+id/levadura_data_notas"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusableInTouchMode="true"
android:focusable="true"
android:textColor="#311b10"
android:textSize="15sp" />
</TableRow>
</TableLayout>
</LinearLayout>
And couldn't show all text on android:id="#+id/levadura_data_mejor".
I don't know why.
For example, I do setText("Trappist Belgian Ales, Dubbles, Tripels and speciality Ales), but only is showing ["Trappist Belgian Ales, Dubbles, Tripels"]
I appreciate your help. Thx
Use android:layout_weight as shown below:
<TextView
android:id="#+id/TextView07"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/levadura_mejor"
android:textColor="#311b10"
android:layout_weight="1"/>
<TextView
android:id="#+id/levadura_data_mejor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:text="Trappist Belgian Ales, Dubbles, Tripels and speciality Ales"
android:layout_weight="1"
android:textColor="#311b10" />
android:singleLine="false"
add the above line.
I am not really shure if this is solving Your problem, I don´t know If You want to make a line break or if You want to scroll the text, if it is longer than the view. But if You want to scroll it, set the following parameters:
android:ellipsize="marquee"
android:marqueeRepeatLimit="-1"
android:singleLine="true"
And in Your Java code class, You have to set Your TextView selected:
yourTextView.setSelected(true);

Achieving the same result without paddingLeft property

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dip" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip"
android:padding="1dip" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="20dp"
android:text="Total Pregnancies"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="30dp"
android:text="10"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="160dp"
android:text="Full Term"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="75dp"
android:text="11"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="190dp"
android:text="Premature"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="30dp"
android:text="12"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/linearLayout1"
android:layout_below="#+id/linearLayout1"
android:layout_marginTop="35dp"
android:padding="1dip" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="20dp"
android:text="Multiples"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="85dp"
android:text="16"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="160dp"
android:text="Living"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="95dp"
android:text="17"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/linearLayout1"
android:layout_centerVertical="true"
android:padding="1dip" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="20dp"
android:text="Ab Included"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="70dp"
android:text="13"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="160dp"
android:text="Ab Spontaneous"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="30dp"
android:text="14"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="190dp"
android:text="Ectopics"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="35dp"
android:text="15"
android:textColor="#000000" />
</LinearLayout>
</RelativeLayout>
This is how the screen looks, can anyone tell me how can i achieve this layout. i have come up with the layout, but it seems it does not fit for all screens.
Make the LinearLayout width fill_parent to use the entire width of the screen.
Then for each TextView, set the layout_width to 0dp, and set layout_weight to the proportion of the screen you want that view to have.
In the padding, specify the minimum amount you want between the different cells.
For example, if you want the text to occupy double the space of the numbers, use the following code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dip" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip"
android:padding="1dip" >
<TextView
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="5dp"
android:text="Total Pregnancies"
android:textColor="#000000" />
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="5dp"
android:text="10"
android:textColor="#000000" />
<TextView
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="5dp"
android:text="Full Term"
android:textColor="#000000" />
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="5dp"
android:text="11"
android:textColor="#000000" />
<TextView
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="5dp"
android:text="Premature"
android:textColor="#000000" />
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="5dp"
android:text="12"
android:textColor="#000000" />
</LinearLayout>
</RelativeLayout>
Use TableLayout
Here is an example

How to increase width of particular EditText in Table Raw (Table layout)

I am using Table Layout.
Here i have three EditText's with same width ="200dp".
But i want to increase the size of 3rd EditText.
I made its width="wrap_content" but all other EditText also getting "wrap_content"
How can i increase the width of 3rd EditText with out affecting other EditText's.
This code for 3rd EditText:-
<TableRow
android:gravity="center_horizontal"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:id="#+id/addl"
android:text="Address"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:id="#+id/colon"
android:text=":" />
<EditText
android:layout_width="250dp"
android:layout_marginLeft="20dp"
android:id="#+id/et"
android:singleLine="true"/>
</TableRow>
Now i want to increase width of Address EditText only
i think you can achieve this by layout_weight parameter of EditTexts like below
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayout12"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#909090"
android:padding="10dp" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Student ID"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text=":"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="6" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text=":"
android:textColor="#000000" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Class"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text=":"
android:textColor="#000000" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Address"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text=":"
android:textColor="#000000" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</TableRow>
</TableLayout>
EDIT
This is the outcome
put the property android:stretchColumns="2" in TableLayout
<TableLayout android:stretchColumns="2" ... > .... </TableLayout>

Alignment issues with TableLayout when adding Buttons

I created a TableLayout for my application. Everything is working fine, but once I add the button image at the bottom of the page the alignment breaks. Here is an image before entering the button image code:
After entering the code for the button images:
My xml layout:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="*"
android:stretchColumns="*"
android:background="#drawable/authenticinfo">
<TableRow
android:id="#+id/tableRow1"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:typeface="serif"
android:textSize="18dp"
android:gravity="center"
android:layout_span="6"></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:typeface="serif"
android:textSize="38dp"
android:gravity="center"
android:layout_span="6"></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:typeface="serif"
android:textSize="38dp"
android:gravity="center"
android:layout_span="6"></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<ImageView
android:id="#+id/imview"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
/>
</TableRow>
<TableRow
android:id="#+id/tableRow5"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:typeface="serif"
android:textSize="20dp"
android:gravity="center"
></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow6"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:id="#+id/ProductID1"
android:text="Product ID"
android:textStyle="bold"
android:typeface="serif"></TextView>
<TextView
android:id="#+id/ProductID2"
android:text=":"
android:textStyle="bold"
android:typeface="serif"></TextView>
<TextView
android:id="#+id/ProductID3"
android:text="92173ad0"
android:textStyle="bold"
android:typeface="serif"></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow7"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:id="#+id/ProductID4"
android:text="产品编号 "
android:textStyle="bold"
android:typeface="serif"></TextView>
<TextView
android:id="#+id/ProductID5"
android:text=":"
android:textStyle="bold"
android:typeface="serif"></TextView>
<TextView
android:id="#+id/ProductID6"
android:text="92173ad0"
android:textStyle="bold"
android:typeface="serif"></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow8"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:typeface="serif"
android:textSize="8dp"
android:gravity="center"
android:layout_span="6"></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow9"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:id="#+id/Manf1"
android:text="生产日期 "
android:textStyle="bold"
android:typeface="serif"></TextView>
<TextView
android:id="#+id/Manf2"
android:text=":"
android:textStyle="bold"
android:typeface="serif"></TextView>
<TextView
android:id="#+id/Manf3"
android:text="01 Jan 2012"
android:textStyle="bold"
android:typeface="serif"></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow10"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:id="#+id/Exp1"
android:text="有效日期 "
android:textStyle="bold"
android:typeface="serif"></TextView>
<TextView
android:id="#+id/Exp2"
android:text=":"
android:textStyle="bold"
android:typeface="serif"></TextView>
<TextView
android:id="#+id/Exp3"
android:text="01 Jan 2015"
android:textStyle="bold"
android:typeface="serif"></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow11"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:typeface="serif"
android:textSize="8dp"
android:gravity="center"
android:layout_span="6"></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow12"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:id="#+id/Mas1"
android:text="马来西亚出口许可证 "
android:textStyle="bold"
android:typeface="serif"></TextView>
<TextView
android:id="#+id/Mas2"
android:text=":"
android:textStyle="bold"
android:typeface="serif"></TextView>
<TextView
android:id="#+id/Mas3"
android:text=""
android:textStyle="bold"
android:typeface="serif"></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow13"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:id="#+id/China1"
android:text="中国的进口许可证 "
android:textStyle="bold"
android:typeface="serif"></TextView>
<TextView
android:id="#+id/China2"
android:text=":"
android:textStyle="bold"
android:typeface="serif"></TextView>
<TextView
android:id="#+id/China3"
android:text=""
android:textStyle="bold"
android:typeface="serif"></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow14"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:typeface="serif"
android:textSize="28dp"
android:gravity="center"
android:layout_span="6"></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow15"
>
<ImageView
android:id="#+id/imbutt"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:background="#+drawable/buttonmainmenuoff"
/>
<ImageView
android:id="#+id/imbutt"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:background="#+drawable/buttonmainmenuoff"
/>
<ImageView
android:id="#+id/imbutt"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:background="#+drawable/buttonmainmenuoff"
/>
</TableRow>
</TableLayout>
The layout breaks because the ImageViews that you add at the end stretch the columns where they are placed(for example the second ImageView that you add will stretch the TextView that holds the :). You don't say how you want them placed but one simple thing that you could do is to wrap them in another layout, like LinearLayout like this:
<TableRow android:id="#+id/tableRow15" >
<LinearLayout
android:layout_span="6"
android:gravity="center" >
<ImageView
android:id="#+id/imbutt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher" />
<ImageView
android:id="#+id/imbutt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher" />
<ImageView
android:id="#+id/imbutt3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher" />
</LinearLayout>
</TableRow>
Of course you could spread them if you want, with the layout_weight attribute.
As a side note, do you really have 6 columns in your layout(you set the layout_span to 6)? Also , do you use those empty singular TextViews or you just use them as dividers(if this is what you want, then you could consider a simple View element outside the TableRows with the desired height)?

Problem with TableLayout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#null">
<ImageView android:layout_width="70dip"
android:layout_height="wrap_content" android:layout_marginLeft="10dip"
android:src="#drawable/photo_profile" android:id="#+id/profil_image"
android:layout_gravity="center" android:layout_marginRight="10dip" />
<TableLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_marginLeft="15dip">
<TableRow>
<TextView android:layout_width="wrap_content" android:text="#string/experience"
android:layout_height="wrap_content" android:textStyle="bold"
android:textColor="#android:color/black" android:textSize="16sp" />
<TextView android:id="#+id/profil_experience"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textColor="#android:color/black" android:textSize="16sp" />
</TableRow>
<TableRow>
<TextView android:layout_width="wrap_content" android:text="#string/secteur"
android:layout_height="wrap_content" android:textStyle="bold"
android:textColor="#android:color/black" android:textSize="16sp" />
<TextView android:id="#+id/profil_secteur"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textColor="#android:color/black" android:textSize="16sp" />
</TableRow>
<TableRow>
<TextView android:layout_width="wrap_content" android:text="#string/lieu"
android:layout_height="wrap_content" android:textStyle="bold"
android:textColor="#android:color/black" android:textSize="16sp" />
<TextView android:id="#+id/profil_lieu"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:singleLine="false"
android:textColor="#android:color/black" android:textSize="16sp" />
</TableRow>
<TableRow>
<TextView android:layout_width="wrap_content" android:text="#string/niveau_etude"
android:layout_height="wrap_content" android:textStyle="bold"
android:textColor="#android:color/black" android:textSize="16sp" />
<TextView android:id="#+id/profil_niveau"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textColor="#android:color/black" android:textSize="16sp" />
</TableRow>
<TableRow>
<TextView android:layout_width="wrap_content" android:text="#string/entreprise"
android:layout_height="wrap_content" android:textStyle="bold"
android:textColor="#android:color/black" android:textSize="16sp" />
<TextView android:id="#+id/profil_societe"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textColor="#android:color/black" android:textSize="16sp" />
</TableRow>
</TableLayout>
<CheckBox android:layout_height="wrap_content" android:id="#+id/profil_checkbox"
android:layout_width="wrap_content" android:layout_gravity="center_vertical" />
</LinearLayout>
and i got this :
http://img11.hostingpics.net/pics/819091Capture.png
I have two problems :
* I can't see the Checkbox
* The text is cutted
and thank you for your attention
You don't have any text in your checkbox. Try adding a text="Some Text" to see if it shows up. I'm guessing since you have it set to wrap_content, you don't actually have any content to wrap.
You can use your TableLayout in a ScrollView of fixed height.so bottom area can be used for CheckBox.

Categories

Resources