LinearLayout问题[Android]

发布于 2024-10-01 03:53:20 字数 743 浏览 4 评论 0原文

好吧,我贬低自己了。这实际上让我感到困惑,因为它在模拟器上显示得很好,但在我的手机上却不行。

在模拟器上,我看到自定义 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

念三年u 2024-10-08 03:53:20

是的,不同的手机会产生不同的结果。我的情况可能就是这样,因为我的手机也超频到 1.2GHz,并且有一个定制的 ROM。不管怎样,解决这个小问题的方法是向添加到布局的视图添加权重规范。

LinearLayout.LayoutParams lpMap = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT); // Verbose!
    lpMap.weight = 0.15f; 

然后我使用以下行而不是上面的行:

layout.addView(_map, 0, lpMap);

我希望这对某人有帮助。这绝对是一个令人困惑的情况,但有时修补是解决方案。虽然我回答了我自己的问题,但非常感谢整个社区。

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.

LinearLayout.LayoutParams lpMap = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT); // Verbose!
    lpMap.weight = 0.15f; 

I then used the following line instead of what I had above:

layout.addView(_map, 0, lpMap);

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文