【问题标题】:Actionbar will not align correctly (RelativeLayout)操作栏无法正确对齐(RelativeLayout)
【发布时间】:2015-08-19 00:58:27
【问题描述】:

我正在尝试将我的 actionbar 设计为在 actionbar 的死点有 textview,以及一个 imageview 在 actionbar 的最右侧,但我无法让图像一直对齐。

无论我更改什么不同的属性,图像都会将我的 textview 向左推,并且会在 imageview 的右侧留下大量空间。

这是 action_bar 自定义 XML 布局,它在我的活动中被夸大了。

[![

<?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>

这是正在发生的事情的一个例子

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    您可以使用工具栏代替操作栏。

    <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>
    

    【讨论】:

    • 问题已解决:)。非常感谢!
    猜你喜欢
    • 2013-08-28
    • 1970-01-01
    • 1970-01-01
    • 2014-07-08
    • 2014-01-08
    • 2011-08-03
    • 2021-03-26
    • 2020-04-17
    • 2014-06-15
    相关资源
    最近更新 更多