Strange XML layout error when setting up on Android 4.3

I have an unusual error with the XML layout file when creating my application when setting the API level to 18. This does not happen with the API level 17. I run the application on Android 4.3 devices, and the error persists on all three devices.

Here's what it looks like:

API 17 (correct):

API 17

API 18 (incorrect):

API 18

I use 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 XML layout 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 know what is going on here? It’s very strange for me that it works when it targets the API level 17 and does not work when targeting the latest API level (18).

Update:

Here's what the visual layout editor with Android 4.3 looks like as a target:

Visual layout editor

+3
android android-xml android-4.3-jelly-bean
source share
3 answers

I managed to solve the problem myself.

As I said, I use the StickyGridHeaders library and reference it in my application. It seems that the library was oriented at the level of API level 17. I changed it to level 18, compiled and launched the application - a great success!

To conclude: Make sure your application and libraries are targeted at the same API level.

+2
source share

I have a problem too. My experience has shown that the cause of the problem is cross alignment (TextView @ + id / seasonTitle has the android property : layout_toLeftOf = "@ + id / episodeCount" ; TextView @ + id / episodeCount has the android properties : layout_alignBottom = "@ + id / seasonTitle" and layout_alignTop = "@ + id / seasonTitle" . One of the layouts will not update its children correctly. Changing the XML template that intersects the alignment is prevented, you no longer have this problem.

+1
source share

I have the same problem:

  • ListView with white background
  • each child has a view with a gray background, width and height up to match_parent, in RelativeLayout

on API 17, everything is fine on API 18+, ListView is white

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

hope this helps

0
source share

All Articles