LinearLayout问题[Android]
好吧,我贬低自己了。这实际上让我感到困惑,因为它在模拟器上显示得很好,但在我的手机上却不行。
在模拟器上,我看到自定义 SurfaceView _map 对象占据了整个屏幕,除了底部的 EditText 文本框(就在它应该在的位置)。当我在我的摩托罗拉 Droid 上运行相同的代码、相同的所有内容时,任何地方都看不到 EditText。
我认为我在 LinearLayout 实现中遗漏了一些东西。到目前为止,我已经轻松学习如何使用另一个 API 的布局管理器。
代码如下:
_map = new Map(this);
_chatText = new EditText(this);
layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 1));
layout.setGravity(Gravity.BOTTOM);
layout.addView(_map, 0);
layout.addView(_chatText, 1);
setContentView(layout);
看起来很简单,所以说实话,我不知道为什么它在实际的 Android 设备上运行时会吃掉我的 EditText。可悲的是,我已经花了很多时间让它在模拟器本身中正确显示。
Okay, I belittle myself. Its actually confusing me because it shows up fine on the Emulator, just not on my phone.
On the emulator, I see the custom SurfaceView _map Object take up the whole screen, except for the EditText text-box at the bottom, right where it should be. When I run the same code, same everything, on my Motorola Droid, there is no EditText to be seen anywhere.
I figure that I am missing something with the LinearLayout implementation I have. Until now, I've gotten off easy on learning how to use another API's layout manager.
Here's the code:
_map = new Map(this);
_chatText = new EditText(this);
layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 1));
layout.setGravity(Gravity.BOTTOM);
layout.addView(_map, 0);
layout.addView(_chatText, 1);
setContentView(layout);
Looks so straitforward, so I honestly don't have a clue why it just eats my EditText when run on an actual Android device. And sadly enough, I've already spent a sad amount of time getting it to show up correctly just in the emulator itself.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,不同的手机会产生不同的结果。我的情况可能就是这样,因为我的手机也超频到 1.2GHz,并且有一个定制的 ROM。不管怎样,解决这个小问题的方法是向添加到布局的视图添加权重规范。
然后我使用以下行而不是上面的行:
我希望这对某人有帮助。这绝对是一个令人困惑的情况,但有时修补是解决方案。虽然我回答了我自己的问题,但非常感谢整个社区。
Yes, different phones will yield different results. And such may have been the case for me, as I also have my phone overclocked to overclocked to 1.2ghz and have a custom rom. Either way, the solution to this little glitch was adding a weight specification to the Views added to the layout.
I then used the following line instead of what I had above:
I hope this helps somebody. Definitely a confusing situation, but sometimes tinkering around is the solution. Although I answered my own question, much thanks to the community at large.