简体   繁体   中英

Which Android control to use?

I'm taking my first steps in Android programming.

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.

Another way to figure out what a native Android activity does is to look at the source code . 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. That style , in turn, uses @android:drawable/bottom_bar as its background. 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.

The contacts layout looks like a ListView sitting on top of some sort of RelativeLayout or LinearLayout housing the buttons. The silver background may simply have been set using android:background on the Layout itself (layouts are views).

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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