2013-02-14 84 views
0

這是我的佈局,我想在動作條顯示:自定義佈局ActionBarSherlock

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

    <EditText 
     android:id="@+id/etSearch" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1.0" 
     android:singleLine="true" /> 

    <ImageButton 
     android:id="@+id/btnSearch" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="0" 
     android:src="@drawable/ic_magnifying_glass" /> 

</LinearLayout> 

這裏的代碼來設置動作條:

@Override 
public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.content_frame); 
     View customNav = LayoutInflater.from(this).inflate(R.layout.custom_action_bar, null); 
     getSupportActionBar().setCustomView(customNav); 
     getSupportActionBar().setDisplayShowCustomEnabled(true); 
     getSupportActionBar().setDisplayShowTitleEnabled(false); 
} 

我預想的TextView填補動作條。 但是,它看起來像這樣:

enter image description here

任何提示?

+0

當你刪除'layout_weight'時會發生什麼? – Sam 2013-02-14 16:43:25

+0

@Sam同樣的結果。 – 2013-02-14 16:47:09

+0

這個問題:[帶有兩個伸展按鈕的Android操作欄](http://stackoverflow.com/q/11264808/1267661)解決了類似的問題。 (接受的答案的佈局讓我感到畏縮,但底部的編輯值得一讀:顯然,ActionBar有自己的[LayoutParams](https://developer.android.com/reference/android/app/ActionBar.LayoutParams.html) ...) – Sam 2013-02-14 16:54:31

回答

0

你有沒有嘗試過: 中的EditText: 機器人:體重= 80

在ImageButton的

: 機器人:體重= 20

反正RelativeLayout的不ActionBarSherlock工作?它更好