【问题标题】:action bar align buttons操作栏对齐按钮
【发布时间】:2014-02-17 07:17:00
【问题描述】:

我有一个带有自定义样式的操作栏的应用程序。在操作栏中,我只有按钮。所以我想在左侧的操作栏中有一个按钮,在操作栏的中心有一个按钮,在操作栏的右侧有一个按钮。我怎样才能对齐它们?

【问题讨论】:

    标签: android button android-actionbar alignment


    【解决方案1】:

    这可能对你有帮助...

    设计一个这样的布局...

    activity_main.xml

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/actionBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:context=".MainActivity" >
    
        <Button
            android:id="@+id/leftButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:text="Left" />
    
        <Button
            android:id="@+id/centerButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="Center" />
    
        <Button
            android:id="@+id/rightButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:text="Right" />
    
    </RelativeLayout>
    

    并像这样将此布局添加到ActionBar...

        ActionBar actionBar = getActionBar();
        actionBar.setDisplayHomeAsUpEnabled(false);
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayUseLogoEnabled(false);
    
        View view = LayoutInflater.from(actionBar.getThemedContext()).inflate(R.layout.activity_main, null);
        ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(layoutParams);
        actionBar.setCustomView(view);
    

    【讨论】:

      猜你喜欢
      • 2015-08-26
      • 2021-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-06
      • 2015-04-02
      • 2017-11-14
      • 1970-01-01
      相关资源
      最近更新 更多