2014-12-30 56 views
-2

我正在嘗試創建一個應用程序。我需要的按鈕是這樣的:如何在android中自定義形狀按鈕?

enter image description here

任何一個可以幫助我創造這樣的按鈕?

編輯:我想,我可能會混淆我的問題語言,我更感興趣的是可佈置的部分和佈局中的這些圖像的位置,請你只幫助我。

+1

看看https://github.com/medyo/fancybuttons並使用/修改它來製作任何想要製作的形狀按鈕。 – kha

+0

您是否問如何使用包含ImageViews的垂直方向的線性佈局? – Theyouthis

回答

0

首先,使用處於按下和未按下狀態的按鈕製作幾張圖像。 然後製作一個垂直LinearLayoutImageViews。 尊敬從R.drawable的圖像只是將您的btn圖像粘貼到您的項目可繪製的文件夾和重建。 然後附上一個onclick聽衆給每個ImageView的:

ImageView img = (ImageView) findViewById(R.id.myImageId); 
img.setOnClickListener(new OnClickListener() { 
    public void onClick(View v) { 
     //change to pressed state 
     img.setImageResource(R.drawable.my_pressed_image); 
     //do action 
    } 
}); 

要旋轉化妝使用下面的代碼:

Matrix matrix = new Matrix(); 
img.setScaleType(ScaleType.MATRIX); //required 
matrix.postRotate((float) angle, pivX, pivY); 
img.setImageMatrix(matrix); 
0

做什麼,我想你問的最簡單方法是將按鈕設置爲圖片。你可以選擇你想要的圖像和尺寸。

爲此,您需要使用ImageButton設置按鈕。

final ImageButton next = (ImageButton) findViewById(R.id.Button01) ; 
Drawable d = Drawable.createFromPath("@drawable/imageForButton"); 
next.enter.setImageDrawable(d); 

雖然由於沒有任何源代碼可以查看,但很難回答這個問題。