对于我的游戏,我正在考虑在我GLSurfaceView使用RelativeLayout的基础上绘制UI元素(TextView用于显示已用时间,按钮用于暂停/重新开始游戏)...
直到现在,我自己直接将所有UI元素绘制到surfaceView,但考虑到Android UI提供的广泛选项(如更改字体和颜色的字体),我决定使用它.
问题:
GLSurfaceView或者直接绘制所有UI内容是否更好GLSurfaceView?TextView通过使用runOnUiThread()方法定期更新UI元素(Say )的内容(每16毫秒)...这是不是很糟糕?这是测试java代码,我用它来设置RelativeLayout ... glView是GLSurfaceView实例.
rl = new RelativeLayout(this);
rl.addView(glView);
tv = new TextView(this);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.ALIGN_TOP);
tv.setLayoutParams(lp);
tv.setText("FPS: 0");
tv.setBackgroundColor(0x4060ff70);
rl.addView(tv);
setContentView(rl);
Run Code Online (Sandbox Code Playgroud) 我能够使用此代码制作自定义吐司
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast_layout, (ViewGroup)findViewById(R.id.custom_toast));
TextView text = (TextView) layout.findViewById(R.id.toast_tv);
text.setText("Hello! This is a custom toast!");
Toast toast = new Toast(getApplicationContext());
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
Run Code Online (Sandbox Code Playgroud)
但是,由于我不明白其目的LayoutInflater,我将代码修改为...
Toast toast = new Toast(getApplicationContext());
toast.setView(findViewById(R.id.custom_toast));
toast.setDuration(Toast.LENGTH_SHORT);
toast.show();
Run Code Online (Sandbox Code Playgroud)
我得到RuntimeException,说"必须调用setView"..
为什么我不能在不使用的情况下将视图分配给toast LayoutInflater?
通常的目的是什么LayoutInflater,以便我可以将此经验应用于其他自定义视图?
编辑:
我在onListItemClick()接口方法中使用这些代码..内容设置后..
我是php的新手(4天前开始学习它),我有很多问题......
我有一个名为index.php的登录页面,在用户名进程登录/验证后,用户被带到chat.php,其中有一个名为someOtherPage.php的其他php页面的链接...我的问题是,如何预防用户直接访问someOtherPage.php而无需登录,只需在网址中输入"www.nameOfMyWebsite.com/someOtherPage.php/"即可
在回答了这个问题之后,我想再问一些关于php的问题......在同一个帖子中问一个稍微不相关的问题(关于标题)是否有效?
我希望每1秒后连续更改一个段落的字体系列.这是我的非工作代码...
<!DOCTYPE html>
<html>
<head>
<script src = "jquery.js"> </script>
<script>
$(document).ready(function() {
var idee = document.getElementById('p1');
changeFont();
});
function changeFont()
{
if(idee.style.fontFamily == 'times')
{
idee.style.fontFamily = 'courier';
}
else if(idee.style.fontFamily == 'courier')
{
idee.style.fontFamily = 'times';
}
setTimeout(changeFont, 1000);
}
</script>
</head>
<body>
<p id="p1">This is some text.</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
那么......我做错了什么?如何有条件地更改字体?