简体   繁体   中英

Android TableLayout is wider than screen width

i am a beginner in creating android apps, so please be kind if my question is to stupid...

I want to make a table which shows some data in a structered way, but my problem is, that i got seven columns and they arent fitting in the screen. So the last coloumn is cutted at it's beginning, this isn't only looking bad, it's also a problem for me, because it's important, that this coloumn ist also shown.

To give ua better view about, what i mean:

I got this code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="*censored*"
android:background="@drawable/gardient_background">

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/scrollView"
    android:layout_alignParentBottom="true"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:scrollbars="none"
    android:overScrollMode="never"
    android:fillViewport="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/representations_table"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:stretchColumns="6"
            android:orientation="vertical">

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

                <TextView
                    style="@style/TableHeaderRow"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/stage_header"
                    android:paddingLeft="5dp"
                    android:ellipsize="end"
                    android:singleLine="true"
                    android:width="25dp"
                    android:textSize="15dp"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/hour"
                    android:id="@+id/hour_header"
                    style="@style/TableHeaderRow"
                    android:paddingLeft="5dp"
                    android:ellipsize="end"
                    android:singleLine="true"
                    android:width="50dp"
                    android:textStyle="bold"
                    android:textSize="15dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/subject"
                    android:id="@+id/subject_header"
                    android:paddingLeft="5dp"
                    style="@style/TableHeaderRow"
                    android:ellipsize="end"
                    android:singleLine="true"
                    android:width="40dp"
                    android:textStyle="bold"
                    android:textSize="15dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/room"
                    android:id="@+id/room_header"
                    android:paddingLeft="5dp"
                    style="@style/TableHeaderRow"
                    android:ellipsize="end"
                    android:singleLine="true"
                    android:width="50dp"
                    android:textStyle="bold"
                    android:textSize="15dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/teacher"
                    android:id="@+id/teacher_header"
                    android:paddingLeft="5dp"
                    style="@style/TableHeaderRow"
                    android:ellipsize="end"
                    android:singleLine="true"
                    android:width="50dp"
                    android:textStyle="bold"
                    android:textSize="15dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/info"
                    android:id="@+id/info_header"
                    android:paddingLeft="5dp"
                    style="@style/TableHeaderRow"
                    android:ellipsize="end"
                    android:singleLine="true"
                    android:width="60dp"
                    android:textStyle="bold"
                    android:textSize="15dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/text"
                    android:id="@+id/text_header"
                    android:paddingLeft="5dp"
                    style="@style/TableHeaderRow"
                    android:ellipsize="end"
                    android:singleLine="true"
                    android:width="30dp"
                    android:textStyle="bold"
                    android:textSize="15dp" />

            </TableRow>

        </TableLayout>
    </LinearLayout>
</ScrollView>

But this gives me:

The Code Result

But I need the last coloumn also inside the screen (u can see a part of the "V" of this coloumn) I know there are some impossible things, like there is to much text, thats why its not possible, but in this case, i want that the text will be shortened with "..." like u see it in the screentshot with the word (Stunde -> Stun...).

So Finally: How can i put the whole table (i dont care if it's crammed), in to the whole screen width?

Please notice: I am not new in programming, i am sure in Java, php, JS, C# etc. I am just bad in desinging and not sure in working with the Android API.

You can try assigning weights to the columns so that they all show no matter what. Other option is to have different views for phone and tablet ie show all the columns only in tablet/landscape view and show the data differently in portrait view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM