Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Actionbar中的ImageView在某些设备中未正确显示_Android_Android Actionbar_Imageview - Fatal编程技术网

Android Actionbar中的ImageView在某些设备中未正确显示

Android Actionbar中的ImageView在某些设备中未正确显示,android,android-actionbar,imageview,Android,Android Actionbar,Imageview,我使用下面的代码在Android的ActionBar中居中显示ImageView。我在几个设备上测试了这个,虽然它在一些设备上正常工作,但在其他设备上却不工作。我附上了从不同设备拍摄的屏幕截图 private void setupActionBar() { ActionBar ab = getActionBar(); ab.setDisplayShowCustomEnabled(true); ab.setDisplayShowTitleEnabled(false);

我使用下面的代码在Android的ActionBar中居中显示ImageView。我在几个设备上测试了这个,虽然它在一些设备上正常工作,但在其他设备上却不工作。我附上了从不同设备拍摄的屏幕截图

private void setupActionBar() {
    ActionBar ab = getActionBar();
    ab.setDisplayShowCustomEnabled(true);
    ab.setDisplayShowTitleEnabled(false);
    ab.setIcon(R.drawable.ic_action_add_person);

    LayoutInflater inflator = (LayoutInflater) this
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflator.inflate(R.layout.action_bar_head, null);
    ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    layoutParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL;
    ab.setCustomView(v, layoutParams);
}
XML是

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:src="@drawable/ic_action_logo" />
</RelativeLayout>

在小米红米1上正常工作 不在Moto E上工作

在xml文件中使用android:layout\u centerInParent=“true”代替android:layout\u centerInHorizontal=“true”更改
android:layout\u height=“wrap\u content”
android:layout\u height=“match\u parent”
是否使用9个补丁图像如果没有,请尝试使用9个补丁可绘制图像