【发布时间】:2014-11-16 13:32:15
【问题描述】:
我正在创建一个自定义操作栏。 它看起来不错,但我有一个奇怪的问题,由于某种原因,右侧的 ImageButton 卡住了,我似乎无法用边距移动它。 这是我的布局 - custom_actionbar.xml:
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/ic_launcher"/>
<ImageButton
android:id="@+id/drawerButton"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="8dp"
android:src="@drawable/drawer_button"
android:background="@null"/>
<ImageButton
android:id="@+id/favouritesButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="8dp"
android:background="@null"
android:src="@drawable/ic_action_important" />
还有我的 MainActivity.java :
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
LayoutInflater mInflater = LayoutInflater.from(this);
View mCustomView = mInflater.inflate(R.layout.custom_actionbar, null);
ImageButton drawer = (ImageButton) mCustomView.findViewById(R.id.drawerButton);
drawer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Drawer Clicked", Toast.LENGTH_LONG).show();
}
});
ImageButton favButton = (ImageButton) mCustomView.findViewById(R.id.favouritesButton);
favButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Fav Clicked", Toast.LENGTH_LONG).show();
}
});
actionBar.setCustomView(mCustomView);
actionBar.setDisplayShowCustomEnabled(true);
}
您可以点击下面的链接查看现在的情况。
picture of how it is right now
我需要将“星”图标向左移动 8dp。 边距在导航抽屉图标中有效,但由于某种原因它不适用于正确的图标。 他离屏幕右侧太近了。
有人知道怎么解决吗?
非常感谢,Refael。
【问题讨论】:
标签: android android-layout android-actionbar