Android : Unable to set TableLayout properly as wanted

久未见 提交于 2019-12-01 10:36:14

I found one thing while solving your problem, about TableLayout when used inside a HorizontalScrollView. The android:stretchColumns is not working when we use Table Layout inside Horizontal Scroll View. So that you are getting blank space when screen is rotated or columns have less width data.

I hope you understand this. I am trying to solve this problem by replacing Horizontal Scroll View with some other. I will post answer if i get solution. Bye.

EDIT

Hi Tvd finally I got the solution for your problem. make below changes to your XML layout file.

In <HorizontalScrollView>

use

        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:fillViewport="true"

Use stretchColumns = "*" in TableLayout if you want all columns to be stretched.

Bye. :-)

I did some changes. some of your problem will solve by below layout code

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

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:scrollbars="horizontal|vertical" >

    <HorizontalScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="10dp" >

        <TableLayout
            android:id="@+id/browseTable"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:background="#FF0000" >
        </TableLayout>
    </HorizontalScrollView>
</ScrollView>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    style="@android:style/ButtonBar"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/browseAddBtn"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginRight="10dp"
        android:layout_weight="1"
        android:text="Add" />

    <Button
        android:id="@+id/browseViewBtn"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginRight="10dp"
        android:layout_weight="1"
        android:text="Edit" />

    <Button
        android:id="@+id/browseReturnBtn"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Return" />
</LinearLayout>

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!