我正在創建一個自定義主頁圖標。對於定製的代碼如下所示,如何刪除自定義視圖前的空間?
View customView = getLayoutInflater().inflate(R.layout.action_bar_display_options_custom, null);
customView.findViewById(R.id.action_home).setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
toggle();
}
});
actionBar.setCustomView(customView, new ActionBar.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
actionBar.setDisplayShowCustomEnabled(true);
這是action_bar_display_options_custom.xml
,
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/action_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/btn_home" />
<TextView
android:id="@+id/action_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> </LinearLayout>
這是截圖,
這是家中的圖標(即空間不是圖像視圖的一部分),
所以,我怎麼能刪除該視圖的前面的空間?
該空間看起來像是圖像視圖的一部分。將背景顏色設置爲紅色,以查看是否屬於這種情況。如果那是真的,你的圖像會以某種方式縮放。否則,可能只需設置負邊距 – seaplain
@Leo Nguyen您可能在父佈局中設置了填充或給定邊距。你可以在第二張圖像之前看到相同數量的空間,因此我想父母的佈局已經有了填充或邊距 – pvn
我有同樣的問題,當我試圖設置自定義操作欄時,我被卡住了問題 'ActionBar bar = getSupportActionBar(); \t \t bar.setDisplayOptions(0,ActionBar.DISPLAY_SHOW_CUSTOM); \t \t bar.setCustomView(view); \t \t bar.setDisplayShowCustomEnabled(true);' – techieWings