Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to display a few tables in a fragment. The smallest table is 5x8 and the biggest is 5x16. Tables display static string resources. If I add a textView for each cell, then there are too many views for one xml layout (Android Studio starts complaining after reaching 80 Views) and if I ignore this warning maybe older/weaker phones will really struggle to show all these views. So I decided to keep only one textView for each column and add to string resources like this:

Table

<TableLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:stretchColumns="*">
<TableRow style="@style/HeaderRow">
                        <TextView android:text="@string/table_header1"
                            style="@style/HeaderText"/>
                        <TextView android:text="@string/table_header2"
                            style="@style/HeaderText"/>
                        <TextView android:text="@string/table_header3"
                            style="@style/HeaderText"
                            android:textAlignment="textStart"/>
                        <TextView android:text="@string/table_header4"
                            style="@style/HeaderText"
                            android:textAlignment="textStart"/>
                        <TextView android:text="@string/table_header5"
                            style="@style/HeaderText"
                            android:textAlignment="textStart"/>
                    </TableRow>
<TableRow style="@style/BottomRow">
                        <TextView android:text="@string/table_column1"
                            style="@style/BodyText"
                            android:textAlignment="textStart"/>
                        <TextView android:text="@string/table_column2"
                            style="@style/BodyText"
                            android:textAlignment="textStart"/>
                        <TextView android:text="@string/table_column3"
                            style="@style/BodyText"
                            android:textAlignment="textStart"/>
                        <TextView android:text="@string/table_column4"
                            style="@style/BodyText"
                            android:textAlignment="textStart"/>
                        <TextView android:text="@string/table_column5"
                            style="@style/BodyText"
                            android:textAlignment="textStart"/>
</TableRow>
</TableLayout>

String example

<string name="table_column1">c1r1

 c1r2

 c1r3

 c1r4

 c1r5 ...</string>

It works and uses minimum amount of views, but I cannot add border or background to individual rows or cells, because it technically has only 2 rows with 4 cells. What would be a better solution in this case?

Also since there are multiple long and wide tables, I use nested/horizontal scrollView and cannot use RecyclerView or ListView.

I also thought about having 2 RecyclerViews, horizontal inside of vertical, without scrollViews, but I don't know how good/bad it is for performance.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
481 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...