2012-04-07 23 views

回答

2

正如布吉所言,爲您的小部件使用自定義背景9貼片可繪製。 第二張圖片由EditText和ImageButton彼此相鄰組成。 對於EditText background drawable for EditText使用9修補程序可繪製,像ImageButton background drawable for ImageButton這樣可以繪製9修補程序。 當然,使用選擇器作爲android:background作爲正常的按鈕和焦點的小工具狀態。

也可以通過使用屬性android:drawableRight來實現第一個圖像。 小工具的已覆蓋onTouchEvent()方法可以是這樣的:

public boolean onTouchEvent(MotionEvent event) { 
    if (event.getAction() == MotionEvent.ACTION_UP && event.getX() >= getWidth() - getCompoundPaddingRight()) { 
     // search drawable was touched 
    } 
    ... 
} 
1

只需使用自己的圖片作爲背景,而不是默認的。

對於EditText視圖我建議看看9-patch,因爲它可以在任何屏幕上順利調整大小。

1

對於後臺我覺得它更容易使用繪製形狀這樣的:

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" > 

    <corners android:radius="10dp" /> 

    <solid android:color="@android:color/white" /> 

    <padding 
     android:left="8dp" 
     android:right="8dp" 
     android:top="8dp" 
     android:bottom="8dp" /> 

</shape> 

半徑給出背景的圓角邊框和可以很容易地調整,所以是改變填充的大小。

相關問題