Android - 填充/保证金存在但未设置

时间:2015-01-08 16:21:09

标签: android xml imageview android-linearlayout relativelayout

我的应用程序中存在一个左侧水平填充,我没有设置,也无法找到如何删除它,对于图像我添加了一个示例图像来说明问题。这就是发生的事情:

enter image description here

这是该作品的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_horizontal" >
<ImageView
    android:id="@+id/actionBarLogo"
    android:layout_width="match_parent"
    android:layout_height="20dp"
    android:layout_gravity="center"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:layout_centerInParent="true"
    android:scaleType="fitXY"
    android:src="@drawable/th2" />

</RelativeLayout>

它也发生在我的主要活动上,但只有大约5dp这很好,因为我在右边添加了5dp。但对于我的行动吧看起来像15dp左右,而且每边都太多了。它会从哪里来?

修改

这是我初始化可操作的

的方式
    android.support.v7.app.ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayUseLogoEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(false);
    LayoutInflater mInflater = LayoutInflater.from(this);
    View myActionBar = mInflater.inflate(R.layout.menu_custom, null);
    android.support.v7.app.ActionBar.LayoutParams layout = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayOptions(actionBar.DISPLAY_SHOW_CUSTOM);
    actionBar.setCustomView(myActionBar, layout);
    actionBar.setDisplayShowCustomEnabled(true);

修改

当我尝试向右添加填充/边距时,左边距/边距增长

修改

我不确定保证金和填充之间的差异,但我认为如果有所作为,它可能是保证金

1 个答案:

答案 0 :(得分:0)

首先,删除android:orientation =“vertical”(不用于相对布局),android:layout_gravity =“fill_horizo​​ntal”(当你有match_parent宽度时不需要), android:layout_gravity =“center”(不在相对布局中使用),android:layout_centerHorizo​​ntal和android:layout_centerHorizo​​ntal(android:layout_centerInParent =“true”就够了)。

其次,这是一个活动布局吗?你在'setContentView()'中直接使用它吗?或者它是在片段内还是在自定义视图内?视图层次结构中的任何级别都可能导致此问题。您可以使用Android Studio中的布局编辑器查找导致它的原因(在查看xml文件时单击“设计”选项卡,然后单击空填充以查看它所属的位置)。如果您无法从中找到它,可以在模拟器上使用层次结构查看器(http://developer.android.com/tools/debugging/debugging-ui.html)并查看错误。