2013-10-15 48 views
0

我已創建了不同的文本要切換按鈕關閉/開啓:切換按鈕上的狀態顯示奇數圖形

<ToggleButton 
     android:id="@+id/PTT_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:onClick="pushtotalk" 
     android:text="@string/ptt" 
     android:textOn="Push To Talk On" 
     android:textOff="Push To Talk Off"/> 

        ... 

public void pushtotalk(View view) { 
    boolean on = ((ToggleButton) view).isChecked();  
    if (on) { 
     Toast.makeText(getApplicationContext(), "this is my Toast message!!! =)", 
     Toast.LENGTH_LONG).show(); 
    } else { 
     // etc 
} 

當肘節是離按鈕看起來確定,但是當我切換在淺藍色出現外箱子,這裏發生了什麼?

enter image description here

編輯:默認切換按鈕,沒有自定義圖像。

編輯也許是與佈局按鈕約束它的事情?

<?xml version="1.0" encoding="utf-8"?> 
<AbsoluteLayout 
android:id="@+id/top_lvl_layout" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#000000" 
xmlns:android="http://schemas.android.com/apk/res/android" 
> 

    <FrameLayout android:id="@+id/mainFrame" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:paddingTop="10dip" 
     android:paddingLeft="6dip" 
     android:paddingRight="6dip" 
     > 

     <!-- (1) inCallPanel: the main set of in-call UI elements --> 
     <RelativeLayout android:id="@+id/inCallPanel" 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent" 
         > 

      <!-- Slide hints: if the "sliding card" feature is enabled, 
       one or the other of these is visible at any given moment 
       (see updateCardSlideHints()). --> 

      <!-- Slide hint and arrow *above* the main body of the card, 
       shown when the card is in the *bottom* position. --> 
      <!-- This hint's position onscreen is static: the Y value is set 
       so that the hint will be visible just above the top edge of 
       the CallCard when the CallCard is in the "bottom" position. 
       The resources here describe the portrait mode layout; see 
       InCallScreen.ConfigurationHelper.applyConfigurationToLayout() 
       for the differences in landscape mode. --> 
      <LinearLayout android:id="@+id/slideUp" 
          android:orientation="vertical" 
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content" 
          android:layout_alignParentBottom="true" 
          android:background="@null" 
          android:visibility="gone" 
          > 
       <TextView android:id="@+id/slideUpHint" 
          android:layout_gravity="center_horizontal" 
          android:gravity="center_horizontal" 
          android:textAppearance="?android:attr/textAppearanceMedium" 
          android:textColor="?android:attr/textColorSecondary" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          /> 
       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center_horizontal" 
        android:src="@android:drawable/arrow_up_float" 
        /> 

      </LinearLayout> 

      <!-- Slide hint and arrow *below* the main body of the card, 
       shown when the card is in the *top* position. --> 
      <!-- This hint's position onscreen is static: the Y value is set 
       so that the hint will be visible just below the bottom edge of 
       the CallCard when the CallCard is in the "top" position. 
       The resources here describe the portrait mode layout; see 
       InCallScreen.ConfigurationHelper.applyConfigurationToLayout() 
       for the differences in landscape mode. --> 
      <LinearLayout android:id="@+id/slideDown" 
          android:orientation="vertical" 
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content" 
          android:layout_alignParentTop="true" 
          android:background="@null" 
          android:visibility="gone" 
          > 
       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center_horizontal" 
        android:src="@android:drawable/arrow_down_float" 
        /> 
       <TextView 
        android:id="@+id/slideDownHint" 
        android:layout_gravity="center_horizontal" 
        android:gravity="center_horizontal" 
        android:textAppearance="?android:attr/textAppearanceMedium" 
        android:textColor="?android:attr/textColorSecondary" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        />     
       <TextView 
        android:id="@+id/stats" 
        android:layout_gravity="center_horizontal" 
        android:gravity="center_horizontal" 
        android:textAppearance="?android:attr/textAppearanceMedium" 
        android:textColor="?android:attr/textColorSecondary" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        /> 
       <TextView 
        android:id="@+id/codec" 
        android:layout_gravity="center_horizontal" 
        android:gravity="center_horizontal" 
        android:textAppearance="?android:attr/textAppearanceMedium" 
        android:textColor="?android:attr/textColorSecondary" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        /> 
      </LinearLayout> 

     </RelativeLayout> <!-- End of inCallPanel --> 

    </FrameLayout> <!-- End of mainFrame --> 

    <!-- The sliding drawer control containing the DTMF dialer. This has been 
     moved so that it is a sibling of mainFrame, instead of being a child. 
     Doing so allows us to expand to the full width of the screen, instead 
     of being confined to the mainFrame's layout --> 
    <SlidingDrawer 
     android:id="@+id/dialer_container" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 

     android:topOffset="5px" 
     android:bottomOffset="7px" 
     android:handle="@+id/dialer_tab" 
     android:content="@+id/dtmf_dialer" 
     android:allowSingleTap="false"> 

     <ImageButton 
      android:id="@id/dialer_tab" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:src="@drawable/ic_dialpad_tray" 
      android:background="@drawable/tray_handle_normal"/> 

     <include 
      layout="@layout/dtmf_twelve_key_dialer" 
      android:id="@id/dtmf_dialer"/> 

    </SlidingDrawer> 


    <ToggleButton 
      android:id="@+id/PTT_button2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:onClick="pushtotalk2" 
      android:text="@string/ptt2" 
      android:layout_x="20dp" 
     android:layout_y="400dp" 
      android:textOn="Push To Talk On" 
      android:textOff="Push To Talk Off"/>  

     <EditText 
     android:id="@+id/editText1" 
     android:layout_width="150dp" 
     android:layout_height="wrap_content" 
     android:layout_x="150dp" 
     android:layout_y="400dp" 
     android:ems="10" > 



     <requestFocus /> 
    </EditText> 

</AbsoluteLayout> 

回答

1

該按鈕的背景圖像是您自己的9patch? 我會建議9patch沒有正確創建。我有一個類似的問題(然而我的自定義組件),並重新繪製9patch幫助。我只是沒有正確繪製定義9patch如何調整大小的黑點。

https://developer.android.com/tools/help/draw9patch.html

+0

謝謝,但這只是一個默認的togglebutton! – Paul

+0

這真的很奇怪。我很好奇當縮短/擴展按鈕的文字時,圖像是如何顯示的? –

+0

在後臺的藍色條只是保持按鈕的長度,認爲這將作爲標準工作: – Paul