2014-09-26 119 views
-3

你好傢伙我知道這不是一個新問題。我從HERE獲得幫助。在我所取得成就,與平面背景圓圈按鈕,但我想要這樣的背景圖像的按鈕:Android:創建帶有背景圖像的圓形外觀按鈕

Sample image

下面是相關的佈局代碼:

<LinearLayout 
    android:id="@+id/viewLayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
    <View 
     android:layout_width="0dp" 
     android:layout_height="2dp" 
     android:layout_weight="1" 
     android:layout_gravity="center_vertical" 
     android:background="@color/lighter_gray"/> 
    <Button 
     android:id="@+id/btnEdit" 
     android:background="@drawable/button_circular" 
     android:ellipsize="none" 
     android:layout_width="0dp" 
     android:layout_weight=".18" 
     android:layout_height="wrap_content" /> 
    <View 
     android:layout_width="0dp" 
     android:layout_height="2dp" 
     android:layout_weight="0.2" 
     android:layout_gravity="center_vertical" 
     android:background="@color/lighter_gray"/> 
</LinearLayout> 

@繪製/ button_circular

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="oval"> 
    <solid android:color="@color/app_main_color"/> 
    <stroke android:width="2dp" android:color="@color/app_main_color" /> 
</shape> 

我也想知道這是一個正確的方式來獲得像這樣的按鈕?提前致謝。

回答

0

您應該使用的ImageView而不是在問題中提到這是一個XML和代碼與題所給按鈕

<ImageView 
    android:id="@+id/btnEdit" 
    android:background="@drawable/button_circular" 
    android:ellipsize="none" 
    android:layout_width="0dp" 
    android:layout_weight=".18" 
    android:layout_height="wrap_content" /> 
+0

的。 – 2014-09-26 05:39:28

+0

這不能解決我的問題 – user3751280 2014-09-26 06:21:18

相關問題