我正在创建一个自定义主页图标。对于定制的代码如下所示,如何删除自定义视图前的空间?
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