本文介绍了三星Galaxy S4的产生位置偏移动作条图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现可视化设计的应用程序,而事实证明,银河S4的产生位置偏移动作条主页图标,这表现在截图:

I'm implementing a visual design for an app, and it turns out that the Galaxy S4 misaligns the actionbar home icon, as demonstrated in the screenshot:

截屏采用两台设备上完全相同的APK文件拍摄。紫色准则坐在16DP从左侧,并且它要的屏幕布局的其余相当重要。在S4增加了一个8DP左右。这种额外的余量,使主页图标还真看的地方。

The screenshots were taken using the exact same APK file on both devices. The purple guideline sits at 16dp from the left, and it is quite important to the rest of the screen layout. The S4 adds another 8dp or so. This extra margin makes the home icon really look out of place.

我已经尝试了很多其他的三星手机在不同的分辨率/密度(银河S3,银河S4迷你,银河ACE)和16DP这些正确对齐所有图标。

I've tried a bunch of other Samsung phones at different resolutions/densities (Galaxy S3, Galaxy S4 Mini, Galaxy Ace) and these all align the icon correctly at 16dp.

我会记在Android的碎片化,继续前进,但银河S4的市场份额是如此之大,我真的不能忽视的问题。有没有其他人遇到了这一点,并找到了解决?

I'd chalk it up to Android fragmentation and move on, but the marketshare of the Galaxy S4 is so big that I can't really ignore the issue. Has anyone else encountered this, and found a fix?

推荐答案

这code是pretty的不言自明的。它首先检查当前设备是三星Galaxy S4模型,基于列表中找到这里。如果是,它然后寻找相关的查看 S的对动作条的布局和层次结构中的家庭 的ImageView 的相对位置。然后转移他们的离开的由(正)偏移参数。它还会检查是否显示自定义查看和转移这一点。唯一的变化是将查看 S' X 坐标,所以它应该与任何主题或风格。

This code is pretty self-explanatory. It first checks if the current device is a Samsung Galaxy S4 model, based on the list found here. If it is, it then looks for the relevant Views based on the ActionBar's layout and the home ImageView's relative position in the hierarchy. It then shifts them left by the (positive) offset parameter. It also checks if a Custom View is displayed, and shifts that as well. The only change is to the Views' x coordinates, so it should work with any theme or style.

private static final String SAMSUNG = "SAMSUNG";
private static final String[] S4_MODELS = {
    "GT-I9506", "GT-I9505G", "SGH-I337", "SGH-M919",
    "SCH-I545", "SPH-L720", "SCH-R970", "GT-I9508",
    "SCH-I959", "GT-I9502", "SGH-N045", "SGH-I337M",
    "SGH-M919V", "SCH-R970X", "SCH-R970C"
};

private void adjustGalaxyS4(int offset)
{
    if (isGalaxyS4())
        shiftHomeView(offset);
}

private boolean isGalaxyS4()
{
    String manufacturer = Build.MANUFACTURER.toUpperCase();
    String model = Build.MODEL.toUpperCase();

    if (SAMSUNG.equals(manufacturer) && !TextUtils.isEmpty(model))
    {
        for (String m : S4_MODELS)
            if (model.contains(m))
                return true;
    }

    return false;
}

private void shiftHomeView(float offset)
{
    try
    {
        View grandParentView = (View) ((View) findViewById(android.R.id.home).getParent()).getParent();
        View upView = ((ViewGroup) ((ViewGroup) grandParentView).getChildAt(0)).getChildAt(0);

        grandParentView.setX(grandParentView.getX() - offset);
        upView.setX(upView.getX() + offset);

        if ((getActionBar().getDisplayOptions() & ActionBar.DISPLAY_SHOW_CUSTOM) != 0)
            getActionBar().getCustomView().setX(getActionBar().getCustomView().getX() - offset);
    }
    catch (Exception e)
    {
        // Fail silently
    }
}

这篇关于三星Galaxy S4的产生位置偏移动作条图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 15:22