2015-01-08 45 views
0

在我的應用程序中存在一個左側水平填充,我沒有設置,也找不到如何刪除它,因爲圖像添加了一個示例圖像來說明問題。這是正在發生的事情:Android - 填充/邊距存在但未設置

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

編輯

當我嘗試填充/保證金添加到右側,左填充/保證金的增長

編輯

我不知道margin和padding之間的差異,但我認爲這可能是保證金,而是如果有差別

回答

0

首先,去掉了Android:方向=「垂直」(不用於相對佈局),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文件時單擊「設計」選項卡,然後單擊空白填充以查看其所屬的位置)。如果你不能從那裏弄清楚,你可以在模擬器上使用Hierarchy Viewer(http://developer.android.com/tools/debugging/debugging-ui.html)並查看出了什麼問題。

+0

這是一個操作欄,但填充的情況也是在我的mainActivity中引起的,它擴展了ActionBarActivity – inVINCEable

+0

你在你的活動中使用了相同的圖片嗎?圖像左側是否有空白? –

+0

我試過多個圖像都產生相同的結果 – inVINCEable