2017-09-06 74 views
-1

我創建了一個簡單的圓形按鈕來爲自定義對話框選取器創建 - 和+按鈕。圓形自定義按鈕中的內聯對齊標題

enter image description here

正如截圖-看到和+移位一點點的時候,在自定義背景的中間不居中。

我在drawable/circular_button.xml中的自定義背景如下所示。

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="oval"> 
    <stroke android:color="@color/colorPrimaryDark" android:width="1dp" /> 
    <solid android:color="@color/colorPrimary" /> 
    <size android:width="30sp" android:height="30sp"/> 

</shape> 

的按鈕配置這樣的LinearLayout

 <Button 
      android:id="@+id/decrease_one" 
      android:layout_width="40sp" 
      android:layout_height="40sp" 
      android:layout_marginRight="20sp" 
      android:background="@drawable/rounded_button" 
      android:text="-" 
      android:textColor="@color/white" 
      android:textSize="30sp" 
      android:textStyle="bold" /> 

內。在我讀到的標籤minHeight的職位之一,但它並沒有解決我的problem.Any想法?

+2

麪糊使用FlaotingActionButton –

+1

它給你帶來更多的好處,而不是你創建一個自定義按鈕 –

回答

2

連擊使用FloatingActionButton迷你

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/activity_my_digital_executor_fabDigitalex" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    card_view:fabSize="mini" 
    card_view:srcCompat="@drawable/ic_new_plus" /> 

在你的應用程序添加'com.android.support:design:26.0.+'相依

0

這是因爲你的按鈕的Android的發生:TEXTSIZE =「30sp」如果設置50SP其下降的線更, 只是轉換你的按鈕來Textviews並設置機器人:比重= 「中心」 還讓你TEXTSIZE 30sp

<TextView 
      android:id="@+id/decrease_2" 
      android:layout_width="40dp" 
      android:layout_height="40dp" 
      android:layout_marginRight="20dp" 
      android:background="@drawable/rounded_button" 
      android:text="+" 
      android:gravity="center" 
      android:textColor="@color/white" 
      android:textSize="30sp" 
      android:textStyle="bold" /> 
+1

應該工作,但是然後你失去了輕拍的「higlighting」效果。 –

-1

如果您使用的是Imageview而不是Textview,那麼問題就解決了。