<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>不規則形狀 &#8211; 記下來</title>
	<atom:link href="https://noter.tw/tag/%E4%B8%8D%E8%A6%8F%E5%89%87%E5%BD%A2%E7%8B%80/feed/" rel="self" type="application/rss+xml" />
	<link>https://noter.tw</link>
	<description>一路上踩到的坑、遇到的問題，一點一滴記下來，希望能幫助到需要的人~</description>
	<lastBuildDate>Tue, 02 Jul 2019 05:43:50 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.3</generator>

<image>
	<url>https://noter.tw/wp-content/uploads/cropped-old-1130742_1920-1-32x32.jpg</url>
	<title>不規則形狀 &#8211; 記下來</title>
	<link>https://noter.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>ImageButton不規則形狀+透明背景</title>
		<link>https://noter.tw/1881/imagebutton%e4%b8%8d%e8%a6%8f%e5%89%87%e5%bd%a2%e7%8b%80%e9%80%8f%e6%98%8e%e8%83%8c%e6%99%af/</link>
					<comments>https://noter.tw/1881/imagebutton%e4%b8%8d%e8%a6%8f%e5%89%87%e5%bd%a2%e7%8b%80%e9%80%8f%e6%98%8e%e8%83%8c%e6%99%af/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Mon, 16 Jan 2012 15:45:21 +0000</pubDate>
				<category><![CDATA[手機 App]]></category>
		<category><![CDATA[onTouchListener]]></category>
		<category><![CDATA[不規則形狀]]></category>
		<category><![CDATA[透明背景]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[ImageButton]]></category>
		<guid isPermaLink="false">http://wazai.net/?p=1881</guid>

					<description><![CDATA[<p>最近跟同事在討論明星臉改版的問題，新版本可能會使用不規則形狀按鈕，繼續跟上一個視覺合作，新版本照照明星臉搭配上這種按鈕顯得更活潑，這篇記錄ImageButton不規則形狀按鈕的使用方法。 上網查了一下&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/1881/imagebutton%e4%b8%8d%e8%a6%8f%e5%89%87%e5%bd%a2%e7%8b%80%e9%80%8f%e6%98%8e%e8%83%8c%e6%99%af/" data-wpel-link="internal">ImageButton不規則形狀+透明背景</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[<p>最近跟同事在討論明星臉改版的問題，新版本可能會使用不規則形狀按鈕，繼續跟上一個視覺合作，新版本照照明星臉搭配上這種按鈕顯得更活潑，這篇記錄ImageButton不規則形狀按鈕的使用方法。</p>
<p style="text-align: center;"><span id="more-1881"></span></p>
<p>上網查了一下該怎麼處理，發現其實並不難，而且只要下關鍵字「不規則形狀 ImageButton」就可以找到非常多的資料，小蛙在這邊記錄一下剛剛測試的，之後如果有什麼其他修改會繼續補充在這邊。<br />
一開始聽到ImageButton要做成不規則形狀好像很困難，網路上找到的做法大多如下：首先我們先建立一個ImageButton，在layou.xml中透過<span style="color: #ff0000;"><strong>android:background=&#8221;#00000000”</strong></span>把背景設定成透明，之後在程式中取得ImageButton的Bitmap元件，在Bitmap上設定OnTouchListener監控觸控事件，當觸控事件發生後再判斷所擊點的座標上有沒有pixel存在，並做相對應的處理。程式碼如下：</p>
<pre class="brush: java; gutter: true">ImageButton img = (ImageButton)findViewById(R.id.imageButton1);
// 取得ImageButton中使用的Bitmap
final Bitmap bitmap = ((BitmapDrawable)(img.getDrawable())).getBitmap();
// 設定觸控螢幕監聽
img.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
&nbsp; &nbsp; &nbsp; &nbsp; // 如果點到的地方getPixel() = 0，表示該點不在圖形內
        f(bitmap.getPixel((int)(event.getX()),((int)event.getY()))==0){
            Log.e("沒有點到", "NO");
        }else{
            Log.e("點到圖片", "Yes");
        }
        return false;
    }
});</pre>
<p>這邊可以再設定一個flag去控制touch(click)只執行一次(避免同個動作會重複多次，從LogCat中就可以看到)。</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/1881/imagebutton%e4%b8%8d%e8%a6%8f%e5%89%87%e5%bd%a2%e7%8b%80%e9%80%8f%e6%98%8e%e8%83%8c%e6%99%af/" data-wpel-link="internal">ImageButton不規則形狀+透明背景</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/1881/imagebutton%e4%b8%8d%e8%a6%8f%e5%89%87%e5%bd%a2%e7%8b%80%e9%80%8f%e6%98%8e%e8%83%8c%e6%99%af/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
