3

I'm experiencing a really peculiar bug with an XML layout file when building my application while targeting API level 18. It doesn't happen with API level 17. I'm running the application on Android 4.3 devices, and the bug persists on all three devices.

Here's what it looks like:

API 17 (correct):

API 17

API 18 (incorrect):

API 18

I'm using the StickyGridHeaders library, and the following is my getHeaderView() method:

@Override
public View getHeaderView(int position, View convertView, ViewGroup parent) {
    RowItem holder;

    if (convertView == null) {
        convertView = inflater.inflate(R.layout.seasons_row_header, parent, false);
        holder = new RowItem();
        holder.title = (TextView) convertView.findViewById(R.id.seasonTitle);
        holder.episodeCount = (TextView) convertView.findViewById(R.id.episodeCount);
        convertView.setTag(holder);
    } else {
        holder = (RowItem) convertView.getTag();
    }

    if (seasons.get(position).equals("00")) {
        holder.title.setText(R.string.stringSpecials);  
    } else {
        holder.title.setText(getString(R.string.showSeason) + " " + seasons.get(position));
    }

    int size = seasonEpisodeCount.get(Integer.valueOf(seasons.get(position)));
    holder.episodeCount.setText(size + " " + getResources().getQuantityString(R.plurals.episodes, size, size));

    convertView.setClickable(false);
    convertView.setFocusable(false);

    return convertView;
}

Here's the layout XML file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#80000000"
    android:padding="@dimen/list_padding" >

    <TextView
        android:id="@+id/seasonTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginRight="@dimen/list_padding"
        android:layout_toLeftOf="@+id/episodeCount"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textIsSelectable="false"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/episodeCount"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/seasonTitle"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/seasonTitle"
        android:gravity="bottom"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textIsSelectable="false" />

</RelativeLayout>

Does anyone else have a clue as to what's going on here? I find it really strange that it's working when targeting API level 17 and not working when targeting the latest API level (18).

Update:

This is what it looks like in the visual layout editor with Android 4.3 as the target:

Visual layout editor

Michell Bak
  • 13,182
  • 11
  • 64
  • 121
  • Have you tried removing this: android:layout_toLeftOf="@+id/episodeCount" I know sometimes cross referencing positions causes weird behaviors... – TacB0sS Sep 11 '13 at 21:44
  • I just tried. It makes the TextView appear, but the other one is rendered on top of it :-( – Michell Bak Sep 11 '13 at 22:28
  • Its a start... :) Try removing the '+' from both @+id/seasonTitle in the episodeCount textview – TacB0sS Sep 11 '13 at 22:40
  • Without trying, I doubt that'll work. The + is needed to create the ID. – Michell Bak Sep 12 '13 at 10:33
  • I was referring to the android:layout_alignBottom="@+id/seasonTitle" and android:layout_alignTop="@+id/seasonTitle" – TacB0sS Sep 12 '13 at 11:22
  • Just tried it - that didn't work either :-( – Michell Bak Sep 12 '13 at 14:45
  • 1
    Just a heads up for anyone encountering this issue (or something similar): it appears to be related to the updated behaviour around how a `RelativeLayout` deals with `MeasureSpec.UNSPECIFIED` in a scroll container (i.e. `ScrollView` or `ListView`). Read the note in the [`RelativeLayout` documentation](http://developer.android.com/reference/android/widget/RelativeLayout.html) for more details, and refer to [#59700 on the Android issue tracker](https://code.google.com/p/android/issues/detail?id=59700). – MH. Sep 17 '13 at 00:05
  • Cheers, MH! It did seem quite strange. – Michell Bak Sep 17 '13 at 11:20

3 Answers3

2

I managed to solve the issue myself.

Like I said, I am using the StickyGridHeaders library and referencing it in my application. It appears that the library was targeting API level 17. I changed it to level 18, compiled and ran the application - great success!

In conclusion: Make sure your application and libraries target the same API level.

Michell Bak
  • 13,182
  • 11
  • 64
  • 121
1

I have the same issue, too. My experiences have shown that crossed alignments are the reason of the problem (TextView @+id/seasonTitle has the property android:layout_toLeftOf="@+id/episodeCount"; TextView @+id/episodeCount has the properties android:layout_alignBottom="@+id/seasonTitle" and layout_alignTop="@+id/seasonTitle". One of the Layouts won't refresh its childs correct. Changing the Layout-XML that crossed alignments are prevented, you no longer have this problem.

5chw4hn
  • 341
  • 3
  • 5
0

I have the same issue :

  • a ListView with a white background
  • each child has a View with a gray background and width and height to match_parent, within a RelativeLayout

on API 17, every is OK on API 18+, the ListView is white

instead of setting a fixed height, I put a min_height to the View, and the problem is (temporary) solved!

hope it helps

STT LCU
  • 4,348
  • 4
  • 29
  • 47