2014-01-26 4 views
1

У меня есть приложение с панелью действий с пользовательским стилем. В панели действий у меня есть только кнопки. Поэтому я хочу иметь одну кнопку в панели действий слева, одну в центре панели действий и одну справа на панели действий. Как я могу их выровнять?кнопки выравнивания панели действий

ответ

2

это может помочь ...

дизайн один макет, как это ...

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); 
Смежные вопросы