2012-10-30 15 views
10

ActionBar, göreceli düzeni kullanırken başlığı göstermiyor. Ve RelativeLayout'u kullanmadığımda, öğeler sağa hizalanmaz. Lütfen menü öğelerini çözüm olarak kullanmamı söyleme. Özel olmalı. İşteÖzel RelativeLayout ile ActionBarSherlock başlık metnini göstermiyor

bunu ayarlamak nasıl:

ActionBar bar = getSupportActionBar(); 
    bar.setDisplayOptions(
      ActionBar.DISPLAY_HOME_AS_UP | 
      ActionBar.DISPLAY_SHOW_CUSTOM | 
      ActionBar.DISPLAY_SHOW_HOME | 
      ActionBar.DISPLAY_SHOW_TITLE | 
      ActionBar.DISPLAY_USE_LOGO); 

    bar.setTitle(title); 
    bar.setCustomView(actionBar); 
    this.setTitle(title); 

hizalama iyi olduğunda bu, ama başlığı buraya

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_alignParentRight="true" > 

     <ImageButton 
      android:id="@+id/acion_add" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/menu_label_add" 
      style="?attr/actionButtonStyle" /> 

     <ImageButton 
      android:id="@+id/action_prev" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/menu_label_prev" 
      style="?attr/actionButtonStyle" /> 

     <ImageButton 
      android:id="@+id/action_next" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/menu_label_next" 
      style="?attr/actionButtonStyle" /> 

    </LinearLayout> 

</RelativeLayout> 

Screenshot

gösterilmiştir Ve edilmez düzenini giriyor başlık gösteriliyor, ancak öğeler

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="right" 
    android:gravity="right"> 

    <ImageButton 
     android:id="@+id/acion_add" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/menu_label_add" 
     style="?attr/actionButtonStyle" /> 

    <ImageButton 
     android:id="@+id/action_prev" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/menu_label_prev" 
     style="?attr/actionButtonStyle" /> 

    <ImageButton 
     android:id="@+id/action_next" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/menu_label_next" 
     style="?attr/actionButtonStyle" /> 

</LinearLayout> 
ile hizalanır.

Screenshot

cevap

12

Ben aynı sorunu vardı ve bu bağlantıyı bulundu: https://groups.google.com/forum/?fromgroups=#!topic/actionbarsherlock/He6gst4nvR0

Bu benim için çalıştı:

düzen:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

    ... 

</LinearLayout> 

kodu:

import com.actionbarsherlock.app.ActionBar.LayoutParams; 
... 
LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.RIGHT | Gravity.CENTER_VERTICAL); 
getSupportActionBar().setCustomView(segmentView, lp); 
0

düzene titleTextStyle ile TextView ekleyerek bir çözümü vardır. Herhangi biriniz daha iyi bir cevabınız varsa, onu görmek için sabırsızlanıyorum.

Benim geçici çözüm

:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <TextView 
     android:id="@+id/player_title" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true" 
     android:layout_toLeftOf="@+id/buttons_holder" 
     android:ellipsize="end" 
     style="@style/TextAppearance.Sherlock.Widget.ActionBar.Title"/> 

    <LinearLayout 
     android:id="@+id/buttons_holder" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_alignParentRight="true" > 

     <ImageButton 
      android:id="@+id/acion_add" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/menu_label_add" 
      style="?attr/actionButtonStyle" /> 

     <ImageButton 
      android:id="@+id/action_prev" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/menu_label_prev" 
      style="?attr/actionButtonStyle" /> 

     <ImageButton 
      android:id="@+id/action_next" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/menu_label_next" 
      style="?attr/actionButtonStyle" /> 

    </LinearLayout> 

</RelativeLayout> 
+0

Ben de aynı şeyi yaptım. Ne yazık ki bu RTL cihazlarda düzgün çalışmıyor. – AsafK

İlgili konular