從Android開發開始,我想知道如何在XML(使用Android Studio)中實現此佈局,目標是4.x Android設備。如何在按比例縮放的背景圖像上定位按鈕
如何精確定位位圖背景上的4個按鈕?應該儘管位圖縮放工作。
場景: 我的應用程序主屏幕應該包含位於位圖上的4個按鈕。按鈕定位應該看起來完全像這樣,並且整個按比例放大/縮小(比例寬度/高度)以匹配屏幕空間。佈局草圖:
嘗試的解決方案:
4按鈕在GridLayout與背景:
<GridLayout android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_centerHorizontal="true" android:orientation="horizontal" android:columnCount="2" android:rowCount="2"> <Button android:id="@+id/button1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Button1" /> <Button android:id="@+id/button2" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Button2" /> <Button android:id="@+id/button3" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Button3" /> <Button android:id="@+id/button4" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Button4" /> </GridLayout>
4按鈕在GridLayout,在一個一個的ImageView以上RelativeLayout的。
- 一個帶有onTouch()的ImageView,用於檢查顏色編碼的位圖。 (source here)
該工作確定關於縮放的onTouch(),但我會用實際的按鈕,使鍵盤導航並按而保留的唯一解決方案/懸停影響正常工作。
如何定位按鈕,使它們始終與位圖匹配? 感謝您的任何見解。
由於標題這個問題看起來像一個愚蠢的,但我還沒有找到任何證明這可以實現。
爲什麼不嘗試相對佈局,而不是網格佈局? – krishna