动作条将无法正确对齐(RelativeLayout的) [英] Actionbar will not align correctly (RelativeLayout)
问题描述
我试图设计我的动作条有在actiobar的死点TextView的,并在最右侧的动作条的ImageView的,但我就是不能让图像对准没事的方式。图像将我推TextView的左,会留下很大的空间给ImageView的右侧不管我改变什么不同的属性。
I am trying to design my actionbar to have the textview in the dead center of the actiobar, and an imageview on the far right of the actionbar, but I just cannot get the image to align all the way right. The image will push my textview left and will leave a lot of space to the right of the imageview no matter what different attributes I change.
下面是这是在我的活动夸大了action_bar自定义XML布局。
Here is the action_bar custom XML layout which is inflated in my activity.
[![
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:weightSum="3"
>
<ImageButton android:src="@drawable/users"
android:background="?attr/actionBarItemBackground"
android:layout_width="24dp"
android:layout_height="24dp"
android:scaleType="centerInside"
android:id="@+id/item2"
android:layout_alignParentRight="true"
android:layout_alignParentTop="false"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Location"
android:id="@+id/textView2"
android:layout_gravity="center_horizontal"
android:textStyle="bold"
android:textColor="#ffffff"
android:layout_centerHorizontal="true" />
</RelativeLayout>
下面是正在发生的事情的一个例子
http://i.stack.imgur.com/mZ8wG.png
Here is an example of what is happening http://i.stack.imgur.com/mZ8wG.png
推荐答案
您可以使用工具栏,而不是行动吧。
You can use toolbar instead of action bar.
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:background="#03a9f4"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
>
<TextView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="14sp"
android:text="@string/profile_setup"
android:id="@+id/title"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="@string/join"
android:paddingRight="24dp"
android:textColor="#ffffff"
android:textSize="14sp"
android:id="@+id/actionButton"
/>
</android.support.v7.widget.Toolbar>
这篇关于动作条将无法正确对齐(RelativeLayout的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!