定位Android 4.3时出现奇怪的XML布局错误 [英] Strange XML layout bug when targeting Android 4.3

查看:120
本文介绍了定位Android 4.3时出现奇怪的XML布局错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在针对API级别18构建应用程序时,我遇到了一个XML布局文件异常的错误。对于API级别17却没有发生。我正在Android 4.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.

这是它的样子:

API 17(正确) :

API 18(不正确):

我正在使用 StickyGridHeaders库,以下是我的 getHeaderView()方法:

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;
}

以下是布局XML文件:

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>

还有其他人对这里发生的事情有任何了解吗?我觉得很奇怪,它在定位API级别17时起作用,而在定位最新的API级别(18)时不起作用。

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).

更新:

这是在以Android 4.3为目标的可视布局编辑器中的外观:

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

推荐答案

我设法自己解决了这个问题。

I managed to solve the issue myself.

就像我说的那样,我正在使用StickyGridHeaders库并在我的应用程序中引用它。看来该库的目标对象是API级别17。我将其更改为18级,编译并运行了该应用程序-取得了巨大的成功!

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!

总结:确保您的应用程序和库针对相同的API级别。

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

这篇关于定位Android 4.3时出现奇怪的XML布局错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆