Home Ask Login Register

Developers Planet

Your answer is one click away!

vipin jain February 2016

How to keep the size of table column be same irrespective of android view

i am adding a table row on button click event. my row has got 2 textview and 2 spinners and 1 EditText. I want the size of the columns to be same, however spinner's size changes as per the selected value. Please help on this and share some lights.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">
    <TableLayout

        android:paddingLeft="5dp"
        android:paddingRight="5dp"
        android:paddingTop="5dp"
        android:stretchColumns="*"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TableRow

            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:paddingLeft="5dp"
            android:paddingRight="5dp">

            <TextView

                android:layout_width="1dp"
                android:layout_height="fill_parent"
                android:layout_weight=".2"
                android:background="@drawable/cell_shape"
                android:padding="5dp"
                android:text="S.No"
                android:singleLine="false"
                android:textAppearance="?android:attr/textAppearanceMedium"></TextView>

            <TextView

                android:layout_width="1dp"
                android:layout_height="fill_parent"
                android:layout_weight=".2"
                android:background="@drawable/cell_shape"
                android:padding="5dp"
                android:text="Product"
                android:textAppearance="?android:attr/textAppearanceMedium"></TextView>

            <TextView

                android:layout_        

Answers


keith February 2016

If the spinner is growing to match the selected value you most probably have layout_width set to wrap_content

It sounds like you should be using something more like layout_weight to correctly use up the horizontal space

Edit: I don't see where this view will scroll if it grows too large. It sounds like you should be using a RecyclerView or ListView instead of your TableLayout. Each item in the list could be something like:

<LinearLayout
    android:layout_height="?android:attr/listItemPreferredHeight"
    android:layout_width="match_parent"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/some_text"
        android:layout_height="match_parent"
        android:layout_width="0dp"
        android:layout_weight="1">
    <TextView
        android:id="@+id/some_more_text"
        android:layout_height="match_parent"
        android:layout_width="0dp"
        android:layout_weight="1">
</LinearLayout>

Note: layout written off the top of my head, may not be perfectly valid :P

You could obviously put controls and weights that match what you want, but from your question I'm assuming this is the expected behavior you seek

Post Status

Asked in February 2016
Viewed 1,181 times
Voted 11
Answered 1 times

Search




Leave an answer


Quote of the day: live life