23

I have three full screen week views that are loaded at one time (previous, next, current). Each week view has 7 columns (one for each day of the week) with a drawable background.

My drawable resource background is

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Grey border on left and right --><item><shape><solid android:color="#999"/></shape></item>
    <!-- White background (.5pt to not cover border) --><item android:left=".5pt" android:right=".5pt"><shape>solid android:color="#FFF"/></shape></item>
    <!-- Image that repeats to make a grid --><item android:left=".5pt" android:right=".5pt"><bitmap android:src="@drawable/grid" android:tileMode="repeat" android:gravity="center" /></item>
    <!-- Times that align left. (12AM, 1AM, etc) --><item android:left="1pt" android:right=".5pt"><bitmap android:src="@drawable/grid_times" android:gravity="top|left|clip_horizontal" /></item>
</layer-list>

For some reason, if I have the three sets of seven in front of each other, only the front (visible one) gets the repeating image (actually a gif). If I shift the front over,, you can see the others do not get the repeating image

Details

The layout is RelativeLayout with three subclasses of RelativeLayout for the children. The three subclasses are identical to each other and override dispatchTouchEvent which allows them to be dragged. They start off right on top of each other so only the front one is visible. They are almost entirely identical except that one of them is on top (at first).

Here is a top view of the android

                ' first    '
                ' second   '
                ' third    '
                |          |#<-- The android screen boundaries. Only third is visible.

                   ^ ^ ^
                    user
                  looking
                  forward

when the user uses their finger to drag the view then it ends up like this (the user can see a little of the first pane (previous week) on the left)

       ' first    '
                           ' second   '
                  ' third    '
                |          |

The other way looks like this (the user can see a little of the second pane (next week))

     ' first    '
                         ' second   '
              ' third    '
                |          |

When the user lets go, they snap to this position (for now,, it will change when we fix this)

     ' first    '
                           ' second   '
                ' third    '
                |          |
Community
  • 1
  • 1
700 Software
  • 85,281
  • 83
  • 234
  • 341
  • Why don't you create the 3 views side by side in a ScrollView? – Marcio Covre Jul 21 '11 at 18:38
  • I could have done that I suppose. but I decided not to. Basically I could use a ScrollView, but if I scrolled all the way to the left, I would have to jump the scrolling to allow the user to go further to the left. This is a calendar system, so the user can go almost infinitely into the past by repeatedly swiping left. If I knew I would have bitmap issues, I might have done that. I would of course need to hide the scrollbar else it would look goofy. [See my other question on the subject if you are interested.](http://stackoverflow.com/questions/4755185) – 700 Software Jul 21 '11 at 18:56
  • 1
    I thought you would want only 3 panels to display, but if you want to display a lot of items and also have a snap to position I would recommend using a Gallery with items screen size, so you get to add items to the Gallery and it will handle all the scrolling for you. – Marcio Covre Jul 25 '11 at 13:37
  • 1
    Only three panels, when I scroll left, the panel on the far right will be moved to the left of the current panel, and its data will be updated. That is described in the linked question. *"This is why I can't use HorizontalScrollView"*. I don't know whether Gallery would work. Will it allow me to remove items from one side and add them to the other side? The number of items rendered at a time should be limited to 3 for memory and performance reasons, and I want an animation affect when the user swipes left or right. – 700 Software Jul 25 '11 at 14:56
  • Gallery will keep only the visible panel and the next and previous on memory, so you can have, for example, 12 items on the gallery for the months of the year and have a selected item number 7 for July, so if the user scrolls left or right the gallery will ask for the views to display. As for animation, the Gallery is like a Horizontal ListView, so you get a scroll only and on scroll stop it has an simple animation to center the item. I think the way you want is what the gallery is, but people think the Gallery is only for images, but can be used for any view and layout. – Marcio Covre Jul 25 '11 at 19:17
  • The docs state that android:gravity is "ignored" when android:tileMode is repeat. Have you tried removing the gravity attribute from that element? – sleep Nov 12 '11 at 10:37

1 Answers1

1

When you shift the front one, invalidate() the others, so they load the drawable.

P Varga
  • 19,174
  • 12
  • 70
  • 108