简体   繁体   English

如何在android 2.2中实现固定位置搜索栏?

[英]How can I implement a fixed position search bar in android 2.2?

I'm trying to write a simple wikipedia app for Android 2.2 which allows users to search and view articles. 我正在尝试为Android 2.2编写一个简单的Wikipedia应用程序,该应用程序允许用户搜索和查看文章。

When a user is viewing an article, I'd like there to be a fixed position search bar that remains fixed at the top of the screen, despite the vertical scroll position, as in this picture: http://img839.imageshack.us/img839/9159/wikidroid01.png 当用户查看文章时,我希望有一个固定位置的搜索栏,尽管它具有垂直滚动位置,但仍固定在屏幕顶部,如下图所示: http : //img839.imageshack.us /img839/9159/wikidroid01.png

How can I implement that search bar? 如何实现该搜索栏? Is it a view I stick in my layout? 我在布局中坚持的观点吗? I've already read about Search Dialog boxes in this android tutorial (http://developer.android.com/guide/topics/search/search-dialog.html)... but it's my understanding that the search dialog box search bar can only show if it is focused (when onSearchRequested() is run), right? 我已经在此android教程(http://developer.android.com/guide/topics/search/search-dialog.html)中阅读了有关搜索对话框的信息,但据我了解,搜索对话框的搜索栏只能显示它是否聚焦(运行onSearchRequested()时),对吗?

Thanks for the help! 谢谢您的帮助!

You can do it by taking relative layout of fixed height. 您可以通过采用固定高度的相对布局来实现。 In that relative layout add the elements in order that you have shown in picture like 1) Imageview with wrap_content height & width. 在该相对布局中,依次添加元素,如图1所示,其中imageview具有wrap_content的高度和宽度。 2) Take Editext with fixed height & width also set Hint for that EditText="Search WikiPedia". 2)以固定高度和宽度的Editext设置该EditText =“ Search WikiPedia”的提示。

Put this layout as first element in your main layout so that it will be always at top if vertical scroll is there it will not scroll that search bar. 将此布局作为主布局中的第一个元素,这样,如果有垂直滚动条,它将始终位于顶部,它将不会滚动该搜索栏。

You can use fragments . 您可以使用片段 They allow you to have 2 (or more) views that are controlled separately. 它们使您可以拥有2个(或更多)单独控制的视图。 Read more here . 在这里阅读更多。

Fragments are new to Android 3.0 however there is a compatibility pack that allows you to use them as early as Android 1.6. 片段是Android 3.0的新功能,但是有一个兼容包 ,可让您最早在Android 1.6上使用它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM