簡體   English   中英

SurfaceView中的多個TextView

[英]Multiple TextViews in a SurfaceView

我正在創建一個Android游戲,我嘗試使用canvas.drawText()方法顯示我的得分和等級,但它導致了錯誤。 現在,我正在嘗試使用TextViews來顯示它們,我正在使用SurfaceVeiw,我想知道是否有可能,並且這將是一個很好的方法。

您不能真正將TextViews放入SurfaceView。 但是,您可以做的是在SurfaceView的頂部添加TextViews。 如果您不知道該怎么做,請告訴我。

// You can use a FrameLayout to hold the surface view
FrameLayout frameLayout = new FrameLayout(this);
frameLayout.addView(surfaceView);

// Then create a layout to hold everything, for example a RelativeLayout
RelativeLayout relativeLayout= new RelativeLayout(this);
relativeLayout.addView(frameLayout);
relativeLayout.addView(textview1);
relativeLayout.addView(textview2);
setContentView(relativeLayout);

添加視圖時,使用LayoutParams幫助組織事物可能會有所幫助。 將此文檔用於LayoutParams。 希望這可以幫助!

如果您使用的是XML布局,則如上所述,我將使用RelativeLayout,將SurfaceView包含在FrameLayout中。 將TextView放置在FrameLayout之上只是為每個視圖配置RelativeLayout參數的簡單問題。 您似乎對Android還是陌生的,也許本指南將在總體上幫助您使用RelativeLayouts和XML布局。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM