5

I'm building an Android App with a timed events and i'm not sure what layout i should use to build my timeline.

Events can have different heights and can grow when user tap them but they have the same width;

              .
              .
              .
------------- |
| Event 4   > | --------------
------------- | < Event 7    |
              | |            |
              | --------------
              .
              .
              .

I have two view types :

  • EventView witch hold the event info and drow his outline
  • TimeBarView witch is the bar on the middle (have some property and is extended on a very long span

How can i place my items so it's respectful of the time on my time-line (for example 1 week could be 10px)

Any help is appreciated. Thanks !

4

2 回答 2

1

I'm tackling the same problem now.

I don't have a full solution yet, but I have an idea:

Since you have to sides to the timeline, ListView is not appropriate because events can overlap.

Instead consider using a 2-column GridView. I recommend using AndroidStaggeredGrid, that support different item sizes.

For the actual "Time bar" that runs in the middle, I'll simply use a narrow line as the background for the GridView.

There will be no markers on the timeline. Instead, the markers will be on the EventView themselves, either on the left or the right, in such a way that the marker falls exactly on the Time Bar.

This way, when you scroll the grid, it will give the illusion that the Time bar itself is scrolling.

To signify an empty time interval, just add an empty view which it's height is proportional to the interval it represents.

Hope it helps...

于 2014-10-16T21:52:09.003 回答
0

I'm not sure there's enough information in your post to determine exactly what's happening during layout, but RelativeLayout will probably do what you need. You can either use leftMargin as an absolute position, or "rules" like RelativeLayout.LEFT_OF

That said, it's very easy to create a custom layout with the Android framework. Just override onMeasure and onLayout. onMeasure should report how large the container is (often, just as large as the parent lets it be), and is pretty straightforward.

onLayout usually looks like this:

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int count = getChildCount();
    for (int i = 0; i < count; i++) {
        View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            // do the layout for each child here, with child.layout
            // e.g., child.layout(0, 0, r, b);
    }
}

View.layout takes 4 arguments - top, left, bottom, and right - pretty simple. You have access to the dimensions of the container in l, t, r and b.

HTH

于 2014-03-09T01:41:25.247 回答