2012-11-05 58 views
0

我在我的android應用程序中爲標題欄定義了以下佈局。Android自定義標題欄按鈕文字不完整顯示

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

    <TextView 
     android:id="@+id/titleTvCenter" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:text="Center" /> 

    <Button 
     android:id="@+id/clearcachebutton" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:text="@string/clear_cache_button_text" /> 

</RelativeLayout> 

這裏我的按鈕沒有完全顯示。任何人都可以幫助我在哪裏出錯。

顯示如下:

enter image description here

在標題欄,因爲你可以看到按鈕文本不正確顯示。

回答

1

試試這個:

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

    <Button 
     android:id="@+id/button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:text="Button" /> 

    <TextView 
     android:id="@+id/titleTvCenter" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:text="Center" /> 

</RelativeLayout> 
+0

我仍然有同樣的問題。 –

+0

請添加所有版面的代碼,但不僅僅是頂部面板(標題欄)。 –

+0

糟糕抱歉,我的錯誤現在工作。 –

1

的問題是,你的Button使用fill_parent佈局的高度。當其父項設置爲wrap_content時,它將僅包裝必要的內容。由於按鈕只是簡單地匹配,而不是堅持它包裝自己的內容,它會被切碎。

只需將Button高度更改爲wrap_content即可設置。

我認爲這是Artyom在回答這個問題時說的,但它不是很清楚。