Jack Jack - 4 months ago 14
Java Question

Change the text size of a TextView and a Column in TableLayout in Android

This is the layout

As you can see, I'm trying to stretch the text box so it will be next to the "NOPE" button. I'm being restricted by the column's size, and the text box's size, which I don't know how to change.

XML:

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

<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >

<Button
android:id="@+id/editBtn"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:layout_column="2"
android:onClick="editEvent"
android:text="EDIT" />

<TextView
android:id="@+id/attendingEventInListviewRow"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_column="38"
android:height="30sp"
android:tag="Events2goName"
android:text="Events2go"
android:textColor="#000000"
android:textSize="22sp"
android:textStyle="normal" />

<Button
android:id="@+id/cancel_arrive"
style="?android:attr/buttonStyleSmall"
android:layout_width="130dp"
android:layout_height="36dp"
android:layout_column="37"
android:layout_gravity="right"
android:layout_weight="0.08"
android:onClick="selectCancelArrive"
android:text="Nope" />
</TableRow>

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" >
</TableRow>

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" >
</TableRow>



Answer

If you set width with hard code using dp it will not work properly with multiple screen. I don't know which screen size you testing you app .. you can set TextView android:layout_width="100dp" it will work for you I hope..

But best is

You can set android:weightSum in TableRow and set android:layout_weight Views under TableRow ... below code is done for you. And it will fit with all screen size..

<TableRow
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:weightSum="10">

    <Button
        android:id="@+id/editBtn"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="0dp"
        android:layout_height="36dp"
        android:layout_column="2"
        android:layout_weight="2"
        android:onClick="editEvent"
        android:text="EDIT" />

    <TextView
        android:id="@+id/attendingEventInListviewRow"
        android:layout_width="0dp"
        android:layout_weight="6"
        android:layout_height="wrap_content"
        android:layout_column="38"
        android:height="30sp"
        android:tag="Events2goName"
        android:text="Events2go"
        android:textColor="#000000"
        android:textSize="22sp"
        android:textStyle="normal" />

    <Button
        android:id="@+id/cancel_arrive"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="0dp"
        android:layout_weight="2"
        android:layout_height="36dp"
        android:layout_column="37"
        android:layout_gravity="right"
        android:layout_weight="0.08"
        android:onClick="selectCancelArrive"
        android:text="Nope" />
</TableRow>