简体   繁体   English

使用哪个Android控件?

[英]Which Android control to use?

I'm taking my first steps in Android programming. 我正在迈出Android编程的第一步。

My application is to create entries in a database. 我的应用程序是在数据库中创建条目。 For this task I have created a new Activity. 为此,我创建了一个新的活动。 All is fine - but I don't really like how it looks. 一切都很好-但我不太喜欢它的外观。

Currently, the emulator shows this: 当前,仿真器显示以下内容:
当前布局

I'd like to have something similar to the "New Contact" Activity: 我想要进行类似于“新联系人”活动的内容:

  • Buttons at the bottom of the window, not directly below the other controls (I'll hopefully figure that out myself) 窗口底部的按钮,而不是其他控件的直接按钮(我希望自己能明白)
  • Buttons within a nice "box" like shown in the screenshot (what's the control hosting the buttons here?) 屏幕截图中显示的是一个不错的“框”中的按钮(此处托管按钮的控件是什么?)
  • When soft-keyboard is displayed, the buttons should "move up". 显示软键盘时,按钮应“向上移动”。 If there's not enough room, the entire area should be scrollable (I'll try and figure that out myself too) 如果没有足够的空间,那么整个区域应该是可滚动的(我也会尝试自己弄清楚)

Sample can be seen here: 示例可以在这里看到:
替代文字

Which control hosts the buttons in the above "New contact" screenshot? 哪个控件托管上述“新联系人”屏幕快照中的按钮? I'd like to use the same for my buttons. 我想对按钮使用相同的按钮。

One way to figure out what an existing activity does is to use hierarchyviewer and examine the activity's contents. 弄清楚现有活动的用途的一种方法是使用hierarchyviewer并检查活动的内容。

Another way to figure out what a native Android activity does is to look at the source code . 弄清Android本机活动的另一种方法是查看源代码 In this case , it would appear that the buttons are inside of a horizontal LinearLayout with style="@android:style/ButtonBar" to give the silver sheen. 在这种情况下 ,似乎按钮位于带有style="@android:style/ButtonBar"的水平LinearLayout内,以提供银色光泽。 That style , in turn, uses @android:drawable/bottom_bar as its background. 相应地,该样式使用@android:drawable/bottom_bar作为背景。 That image can be found in your SDK installation -- go to the platform directory of your choice, then data/res/drawable-hdpi and data/res/drawable-mdpi for the two versions. 可以在SDK安装中找到该映像-转到您选择的平台目录,然后转到两个版本的data/res/drawable-hdpidata/res/drawable-mdpi

The contacts layout looks like a ListView sitting on top of some sort of RelativeLayout or LinearLayout housing the buttons. 联系人布局看起来像ListView,位于某种形式的RelativeLayout或LinearLayout的顶部,其中包含按钮。 The silver background may simply have been set using android:background on the Layout itself (layouts are views). 银色背景可能只是使用Layout本身上的android:background设置的(布局是视图)。

I found that the commonsware books are excellent resources for getting started and have good examples for this type of layout. 我发现常用软件书籍是入门的绝佳资源,并提供了此类布局的良好示例。

Hey, this is a little late, and I know you've already got the silver bar you wanted, which is all good, but I've stumbled upon a really good guide on controlling the soft keyboard for best user experience . 嘿,这有点晚了,我知道您已经有了想要的功能,这一切都很好,但是我偶然发现了一个非常好的指导,旨在控制软键盘以获得最佳的用户体验 It covers, among other things, how to make the visible area resize to fit the button bar in the view while typing, which is done by specifying the activity in the manifest file like so: 除其他事项外,它涵盖了如何在键入时调整可见区域的大小以适合视图中的按钮栏,这是通过在清单文件中指定活动来完成的,如下所示:

<activity android:name=".MyActivity" android:windowSoftInputMode="resize" />

I really recommend reading it, it covers a lot more helpful stuff than just that. 我真的建议您阅读它,它不仅涵盖了更多有用的内容。 Hope that helps; 希望能有所帮助; I couldn't see that anyone else has answered that particular part of your question. 我看不到其他人回答了您问题的特定部分。

You can put them in LinearLayout and assign weight of 1 to each of the buttons. 您可以将它们放在LinearLayout中,并为每个按钮分配1的权重。 Also if you own dev phone / or want to see UI of the application in emulator - there is a very cool tool call hierarchyviewer http://developer.android.com/guide/developing/tools/hierarchy-viewer.html and you can see how UI of app you like has been laydown. 另外,如果您拥有开发电话/或希望在模拟器中查看应用程序的用户界面,则有一个非常酷的工具调用hierarchyviewer http://developer.android.com/guide/developing/tools/hierarchy-viewer.html ,您可以查看您喜欢的应用的用户界面如何放下。

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

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