Closed Nefariis closed 5 years ago
To be honest, I have no idea. But there are two things I would try to do:
1) As the TableView is a LinearLayout, I would try to apply the LinearLayout.LayoutParams instead of the FrameLayout.LayoutParams.
2) In addition I would try to request layout on the scroll views after changing the tables width.
So when I switch it to LinearLayout.LayoutParams
instead of FrameLayout.LayoutParams
I receive this crashing error -
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.FrameLayout$LayoutParams`
Here is how I have tried to do the update/refresh -
// This is for the Table
table.invalidate()
table.postInvalidate()
table.refreshDrawableState()
table.requestLayout()
table.forceLayout()
table.visibility = GONE
table.visibility = VISIBLE
// This is for the HorizontalScrollView
container.invalidate()
container.postInvalidate()
container.refreshDrawableState()
container.requestLayout()
container.forceLayout()
container.visibility = GONE
container.visibility = VISIBLE
I figured out a solution in case anyone needs to accomplish this -
On the SortableTable I changed the android:layout_width
to "fill_parent"
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<de.codecrafters.tableview.SortableTableView
android:id="@+id/tableView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="14sp"
custom:tableView_headerElevation="14">
</de.codecrafters.tableview.SortableTableView>
</HorizontalScrollView>
And then I implemented a method to change the column width depending on which columns were displayed (taken from the main page)
TableColumnDpWidthModel columnModel = new TableColumnDpWidthModel(context, 4, 200);
columnModel.setColumnWidth(1, 300);
columnModel.setColumnWidth(2, 250);
tableView.setColumnModel(columnModel);
Using this method, invalidate
or requestLayout
are not necessary and the SortableTable
increases/decreses size according to the columns that are displayed.
Thank you again for the help and the quick response
Thanks for sharing! :)
[<HorizontalScrollView
android:id="@+id/lresult"
android:layout_below="@+id/l1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<de.codecrafters.tableview.SortableTableView
android:id="@+id/result"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="6sp"
>
</de.codecrafters.tableview.SortableTableView>
</HorizontalScrollView>](url)
I am unable to change the textsize of the table view I want to make the textsize small. How can i do it? @ISchwarz23 @OoElectron please help!!
Are you using the SimplaTableDataAdapter
.
Yes sir @ISchwarz23
Then you can use the SimpleTableDataAdapter#setTextSize( int )
method.
Thank u sir :) It's working
Is it possible to change the size of the table programatically?
Here is how I am implementing my table -
Which is working fine, but the table can have anywhere from 2-8 columns - so 900dp looks great for 5-8 columns but looks funny for 2-4 columns.
I've tried changing the table size like a normal element but it doesnt seem to be working.
I can tell it wants to work though, when I wrap it with
I get this in my Logcat
So you can see the width is going from 2475 to 100 - but its not changing on the screen.
I've tried invalidating, post invalidating, and refreshing/redrawing the activity to no avail.
I was hoping you have an idea of how I might accomplish this?
Thank you and thank you again for the wonderful library.