简体   繁体   English

Android TableLayout比屏幕宽度宽

[英]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... 我是创建android应用的初学者,所以如果我的问题是愚蠢的,请保持友善...

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...). 但是我也需要屏幕上的最后一个对话框(您可以看到该对话框“ V”的一部分),我知道有一些不可能的事情,例如文本太多,这就是为什么它不可能的原因,但是在这种情况下,我希望文本以“ ...”缩短,就像您在截屏中看到的那样(单词“ 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. 请注意:我不是编程新手,我确定使用Java,php,JS,C#等。我在设计上很糟糕,不确定使用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. 另一种选择是使电话和平板电脑具有不同的视图,即仅在平板电脑/横向视图中显示所有列,并在纵向视图中以不同方式显示数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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