我正在設計一個GUI遠程控制,但不是爲每個遠程按鈕製作單獨的按鈕,我想獲得一個完整的準備好的遠程圖像並設置其可點擊的某些部分。 有沒有一種方法,而不是運動事件來做到這一點?可點擊的圖像區域
可點擊的圖像區域
回答
我有2個解決方案爲您的requirements.in兩個,整個圖像保持點擊,但你可以得到有關點擊區域的信息。
解決方案1:
可以屏蔽圖像和獲取下image.so的像素顏色最終你可以來了解被點擊哪個區域。
這裏,無論何時發生點擊,您都可以檢查background image
的像素顏色,並將其與預定義的顏色設置相匹配,以瞭解哪個區域已被點擊。
前景畫面:
背景畫面:
可點擊區域:
還是糊塗?
參考: 我想建議你去通過this教程。
解決方案2:
你可以用座標映射圖像,因此你可以得到已被點擊區域的信息。
例子: MappedImage與座標
,如果你不知道座標,你可以創建here
座標爲堪薩斯您mappedimage會是這個樣子,
<area shape="poly" coords="243,162,318,162,325,172,325,196,244,196" id="@+id/area14" name = "Kansas"/>
參考: 請看看Android Image Mapping。
我希望它會有幫助!
好的,謝謝.......我會很快測試 –
感謝您的支持!任何想法如何在鈦合金應用程序中使用這些方法? – learner123
如果我們必須放大圖像並獲得像素,該怎麼辦?它會返回相同的顏色嗎? –
您仍然可以使用按鈕。
你可以將它們放在你的圖像上的正確位置,並使它們不可見。
在XML
<Button android:visibility="invisible"/>
或者
Button mybutton = (Button) v1;
mybutton.setVisibility(View.INVISIBLE);
我有同樣的挑戰,並與庫"PhotoView",在那裏你可以聽
onPhotoTap(View view, float x, float y){}
事件,並檢查是否解決了它該選項卡位於圖像區域內,然後執行某些任務。
我創建了一個庫來幫助其他開發人員更快地實現此類功能。它位於Github上:ClickableAreasImages
此庫允許您定義圖像中的可點擊區域,將對象與其關聯並偵聽該區域的觸摸事件。
如何使用圖書館:
public class MainActivity extends AppCompatActivity implements OnClickableAreaClickedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Add image
ImageView image = (ImageView) findViewById(R.id.imageView);
image.setImageResource(R.drawable.simpsons);
// Create your image
ClickableAreasImage clickableAreasImage = new ClickableAreasImage(new PhotoViewAttacher(image), this);
// Initialize your clickable area list
List<ClickableArea> clickableAreas = new ArrayList<>();
// Define your clickable areas
// parameter values (pixels): (x coordinate, y coordinate, width, height) and assign an object to it
clickableAreas.add(new ClickableArea(500, 200, 125, 200, new Character("Homer", "Simpson")));
clickableAreas.add(new ClickableArea(600, 440, 130, 160, new Character("Bart", "Simpson")));
}
// Listen for touches on your images:
@Override
public void onClickableAreaTouched(Object item) {
if (item instanceof Character) {
String text = ((Character) item).getFirstName() + " " + ((Character) item).getLastName();
Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
}
}
...
}
如果我需要檢查非矩形區域(如圓圈)中的點擊,該怎麼辦?它與你的圖書館一起工作嗎?謝謝。 – trinity420
提高@sealz回覆,在這裏我的答案:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_centerInParent="true"
android:layout_alignTop="@+id/mail"
android:layout_alignBottom="@+id/mail"
>
<Button
android:id="@+id/leftMail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".5"
android:background="@android:color/transparent"
/>
<Button
android:id="@+id/rightMail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".5"
android:background="@android:color/transparent"
/>
</LinearLayout>
<ImageView
android:id="@+id/mail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/mail1600x600"
android:layout_centerInParent="true"
/>
</RelativeLayout>
- 1. 可點擊區域圖像
- 2. 試圖使圖像區域可點擊
- 3. 圖像中的Android可點擊區域
- 4. 可變圖像大小的可點擊圖像區域
- 5. 圖像具有多可點擊區域/表面/區域
- 6. 增加圖片的可點擊區域
- 7. .JPEG圖片中的可點擊區域?
- 8. 圖像地圖上的可點擊區域
- 9. 如何在Android中使圖像可見區域可點擊?
- 10. 的Java的JButton圖像PNG可點擊區域
- 11. Android在圖像中的形狀窗體的可點擊區域
- 12. 進行佈局的背景圖像的可點擊區域
- 13. HTML中圖像的可點擊區域的名稱
- 14. 在無序列表中增加可點擊的圖像區域
- 15. MenuItem可點擊區域
- 16. 與可點擊區域
- 17. 圖片地區沒有變成可點擊區域的圖像映射
- 18. 在ListView項目中設置圖像多個可點擊區域?
- 19. 錨標記可點擊區域比圖像內
- 20. 在圖像中創建可點擊區域?
- 21. 以編程方式在圖像上創建可點擊區域
- 22. 在背景圖像上設置可點擊區域
- 23. 設置圖像錨可點擊區域,圈
- 24. 在圓形JLabel圖像周圍創建可點擊區域
- 25. 使可點擊區域在畫布上改變圖像
- 26. 可定位的可點擊區域
- 27. IMG熱點 - 啓用可點擊區域
- 28. WPF中的圖像地圖/自定義形狀的可點擊區域 - WP7
- 29. 觸發圖像地圖區域的點擊行爲
- 30. Firefox中的小可點擊區域
你想使這一切在一個圖像? – kabuto178
@ kabuto178是的.... –
是他們以某種方式將圖像分割爲行和列的方式? –