[英]How to divide Android game screen
我正在開發游戲應用程序,並且使用horizontal orientation
。
我使用屏幕的左1/3來顯示分數和控件,並使用右2/3來顯示我的游戲板。
我的游戲照常運行,但是我目前使用單個畫布來顯示所有內容。 這使我的游戲邏輯更加復雜,因為在顯示任何圖形時必須始終增加屏幕寬度的1/3。
似乎* 我應該能夠定義卵石 * n的2個部分 (左1/3和右2/3),也許使用兩個畫布,以便每個部分為我提供一個從0,0開始的獨特坐標系。 這將使我的游戲協調數學更加容易。
我可以在一個活動中使用多個畫布嗎? 我可以把它們放在我想要的任何地方嗎?
謝謝
您可以在線性布局中使用權重,該權重用於按所需比例划分布局http://developer.android.com/guide/topics/ui/layout/linear.html#Weight Fragments http://developer.android.com /reference/android/app/Fragment.html
使用片段進行第二次布局
例
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.33333"
android:background="@android:color/holo_blue_bright" >
</LinearLayout>
<LinearLayout
<--fragment here -->
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.6666"
android:background="@android:color/holo_green_dark" >
</LinearLayout>
</LinearLayout>
您可以使用片段來划分屏幕。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.