InQBarna / TableFixHeaders

Android library that implements a table with fixed headers.
Apache License 2.0
819 stars 300 forks source link

Orientation changes support #45

Open IsaacCisneros opened 10 years ago

IsaacCisneros commented 10 years ago

Hello,

Thanks for sharing this cool library. I'm interested in using your library for my app that supports both orientations. When I execute the example and select the "Family adapter" option I experience a weird behavior. The steps to reproduce are:

Result: Cells are displayed wrong, after scrolling some of them are resized to its original size, however some cells in the column header row never restore their original size.

Many thanks.

BraisGabin commented 10 years ago

I can't reproduce it.

Are you using the master version? Device? API level? Screen shoots?

IsaacCisneros commented 10 years ago

These are my settings: -Master version. -Galaxy Nexus (API level 17) -Galaxy S3 (API level 16)

step 1: Portrait orientation, scroll until the end in the X axis. 01

step 2: rotate screen to landscape. 02

step 3: In landscape scroll in any direction: 03

cheers

BraisGabin commented 10 years ago

Do both mobiles use CyanogenMod? I don't know the reason of that behavior.

liujmok commented 10 years ago

I'm having the same problem, i recalculated the tableFixHeaders.firstcolumn in the onConfigurationChanged().

Is there a better way to do it?

BraisGabin commented 10 years ago

I can't reproduce this issue. Can you give me some sample code?

liujmok commented 10 years ago

This may not be bug, about the user experience.

FamilyTable

    <activity
        android:name="com.inqbarna.tablefixheaders.samples.FamilyTable"
        android:label="@string/family_adapter" android:configChanges="orientation|screenSize">
    </activity>

and add more columns of data.

1.portrait orientation, scroll to the right most of the table.

2.rotate screen to landscape, when a table has many columns of data, i want to keep the table in the right position does not change. but FamilyTable the right blank.

or 3.i recalculated the tableFixHeaders.firstcolumn

public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    //DisplayMetrics metric = new DisplayMetrics();
    //getWindowManager().getDefaultDisplay().getMetrics(metric);        
    //int w = metric.widthPixels;
    //int h = metric.heightPixels;

    tableFixHeaders.firstColumn = 8;
    ((BaseTableAdapter)tableFixHeaders.getAdapter()).notifyDataSetChanged();
}

if the calculated error occurs above problem

Can you give me any suggestions?

BraisGabin commented 10 years ago

Save scroll position. I'll implement this some day.

Did you try scrollTo()? I don't recommend you to change firstColumn value directly.

ashx1 commented 10 years ago

I don't know if this will work but try it, its worth a shot:

Just before the orientation changes, call the methods: TableFixHeaders.getActualScrollX() and TableFixHeaders.getActualScrollY() and save the values returned into local variables.

Once the orientation change has completed, just call: TableFixHeaders.scrollTo(..) providing the values saved in the local variables and it should scroll to that X and Y position.

MariuszGSL commented 10 years ago

Yes, this is exactly what I do in my application. I use: TableFixHeaders.scrollTo(0, LastRowPosition) 0 indicates that it should always scroll horizontally to the first column position (e.g. after orientation change). The LastRowPosition is calculated by multiplying the row number: (xxxx.row_ids.indexOf(m_id) by the RowHeight, to get the precise vertical scroll position. You can see it in action in my app: https://play.google.com/store/apps/details?id=com.eliteherd.elitemobile

liujmok commented 10 years ago

I used tableFixHeaders.scrollTo(Integer.MAX_VALUE, 0), It still did not work.

ashx1 commented 10 years ago

Was this after the orientation change because it should work?

MariuszGSL commented 10 years ago

@liujmok You have got the scroll parameters entered in the wrong order: The first value should be zero (horizontal scroll) and the second value should be set to the max vertical scroll. See below: TableFixHeaders.scrollTo(0, Integer.MAX_VALUE) See also my note above. You have got these values set back to front.