artist
artist

Reputation: 6381

How to increase the height of table row according to screens?

I would like to know how can I increase the height of table row so it looks proportionate in larger screen sizes. Currently all of the textviews and edittexts(placed in table rows) appear on the left side of the screen instead of occuping the whole screen( only in larger screen sizes). Here is the xml I am working with:

<ScrollView android:id="@+id/ScrollView01" 
  android:layout_width="fill_parent" 
  android:layout_height="fill_parent" 
  xmlns:android="http://schemas.android.com/apk/res/android">     

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"

    android:layout_height="fill_parent" android:background="@color/black_background">

<TableLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent"
    >
  <TableRow    android:id="@+id/TableRow01" 
               android:layout_width="fill_parent" 
               android:layout_height="wrap_content" >


  <TextView  android:id="@+id/name"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:textSize="20sp"
             android:textColor="@color/white" 
             android:visibility="visible" 
             android:text="@string/Name" 
             android:layout_weight="0.2"
             android:layout_marginLeft="20dp" 
             android:layout_marginTop="22dp"/>

 <EditText   android:id="@+id/myName"
             android:layout_width="120dip"
             android:layout_height="wrap_content"
             android:textSize="20sp"
             android:visibility="visible" 
             android:layout_weight="0.3"
             android:inputType="number" 
             android:textColor="@color/black_background" 
             android:layout_marginLeft="10dp" 
             android:layout_marginTop="10dp"/>

 <TextView   android:id="@+id/error1"
              android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:textSize="18sp"
             android:textColor="@color/red" 
             android:visibility="visible" 
             android:layout_weight="0.5"/>

  </TableRow>
 <TableRow    android:id="@+id/TableRow02" 
               android:layout_width="fill_parent" 
              android:layout_height="wrap_content">


  <TextView  android:id="@+id/address"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:textSize="20sp"
             android:visibility="visible"
             android:textColor="@color/white" 
             android:text="@string/address" 
             android:layout_weight="0.2"
             android:layout_marginLeft="20dp" android:layout_marginTop="22dp"/>

 <EditText   android:id="@+id/address"
             android:layout_width="120dip"
             android:layout_height="wrap_content"
             android:textSize="20sp"
             android:visibility="visible" 
             android:inputType="number" 
             android:textColor="@color/black_background" 
             android:layout_weight="0.8"
             android:layout_marginLeft="10dp" android:layout_marginTop="10dp"/>

  </TableRow>
</TableLayout>           

    </LinearLayout>
 </ScrollView> 

Upvotes: 14

Views: 47722

Answers (6)

frogatto
frogatto

Reputation: 29285

Add the following properties to all your TableRows:

android:layout_height = "0dp"
android:layout_weight = "1"

It stretches all your TableRows to occupy the entire parent height.

Upvotes: 4

Mike
Mike

Reputation: 785

Use

android:minHeight="60px"

On TableRow tag

<TableRow android:id="@+id/task1" android:layout_width="fill_parent"
          android:minHeight="60px" android:layout_height="wrap_content">

Upvotes: 30

jiasli
jiasli

Reputation: 9138

You can set the android:layout_weight of each TableRow to 1. Then change the height of TableLayout as you like. It works fine for me!

android:layout_weight="1" 

Upvotes: 1

munna
munna

Reputation: 71

Please go through this link, i think it will help you out. http://developerlife.com/tutorials/?p=307

Please note that the children of a TableLayout cannot specify their width – which is always FILL_PARENT. However, the height can be defined by a child, which defaults to WRAP_CONTENT. If the child is a TableRow, then the height is always WRAP_CONTENT.

So if you use TableLayout with TableRows you can’t really can’t set the width/height (width=FILL_PARENT, and height=WRAP_CONTENT).

By the way, a TableRow is just a subclass of LinearLayout. What you can do is specify the behavior of the column to shrink and/or stretch or not. You can also hide a column by calling setColumnCollapsed on a TableLayout, and passing it the column index. All column indices start at 0, and you can have empty columns.

Upvotes: 7

Ashish Chauhan
Ashish Chauhan

Reputation: 39

You can apply android:layout_weight to TableRow and give equal value to all table rows. Table rows will be distributed in remaining space of linear layout.

Ensure, you have set below attributes to TableLayout

android:layout_width="match_parent"
android:layout_height="match_parent"

Upvotes: 0

Jim
Jim

Reputation: 833

You can just use android:layout_weight. In the code below for example, the left button is twice as big as the right button:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent">
    <Button android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"
            android:text="hai" />
    <Button android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="2"
            android:text="longer sentence" />
</LinearLayout>

Upvotes: 4

Related Questions