我在Xamarin.Android中创建了一个布局,我正在使用图像按钮TextView和另一个标签来自定义工具栏。我需要做的是确保图像按钮BackButton一直左对齐到父容器的左侧,TextView是中心对齐,并且MenuButton图像按钮右对齐一直到父容器的右侧。下面你会看到我在设计模式的看法:如何在Android xml中自定义工具栏上对齐UI控件
axml代码:
<?xml version="1.0" encoding="utf-8"?>
<Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ToolBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/actionBarSize"
android:background="?android:attr/colorPrimary"
android:theme="@android:style/ThemeOverlay.Material.Dark.ActionBar"
android:popupTheme="@android:style/ThemeOverlay.Material.Light">
<ImageButton
android:id="@+id/BackButton"
android:layout_width="wrap_content"
android:background="@drawable/RedButton"
android:layout_height="wrap_content"
android:layout_marginLeft="1dp"
android:src="@drawable/back48x48"
style="@style/back_button_text" />
<TextView
android:id="@+id/AppNameView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:textColor="#ffffff"
android:layout_marginLeft="18dp"
android:layout_marginRight="12dp"
android:textSize="25dp"
android:text="Just a Label ok" />
<ImageButton
android:id="@+id/MenuButton"
android:layout_width="wrap_content"
android:layout_marginLeft="2dp"
android:layout_centerVertical="true"
android:background="@drawable/RedButton"
android:layout_alignParentRight="true"
android:gravity="right"
android:layout_height="wrap_content"
android:src="@drawable/menu48x48"
style="@style/menu_button_text" />
</Toolbar>
刚上最好办法好奇地做到这一点。
这是越来越称为在另一axml的方式如下包括:
RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center_vertical|center_horizontal">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:rowCount="3"
android:columnCount="3">
您是否指的是我所做的包括xml abover?否则,ImageButton的父对象是一个工具栏 – yams
对不起,我误解了你的问题,我现在编辑我的回答 –
这没有奏效。这使得相对布局比宽度上的工具栏略小,并使MenuButton ImageButton消失在屏幕之外。 – yams