2012-01-07 66 views
0

我如何在xml中定位一个按钮。即时通讯与android SDK的使用Eclipse,我只是用边缘把按钮的位置。但我怎样才能通过postion功能呢?示例XML位置函数?

+0

你能详细说明你正在尝试使用哪个api吗? – nandeesh 2012-01-07 21:46:48

+0

试图调试应用程序,并没有得到任何筛选 – 2012-01-07 22:06:51

+0

所有即时通讯试图将按钮放在固定位置 – 2012-01-07 22:07:15

回答

1

使用xml在屏幕上放置按钮将取决于您对根视图组使用的内容。

没有一个位置函数,比如你可能想要在哪里设置按钮的X和Y位置,并且有很好的理由。由于Android设备的硬件碎片化,如果您依靠硬编码的X和Y坐标(无论纵向还是横向),编写便携式UI将会非常困难。

举个例子,如果我想提出一个按钮在屏幕的右下方,我有一个相对布局:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/hello" 
    android:layout_alignParentBottom = "true" 
    android:layout_alignParentRight = "true"/> 
</RelativeLayout> 

这将会把一个按钮在屏幕上的按钮右侧,无论画面像素密度/分辨率甚至风景VS人像

+0

谢谢!除了如果我想集中它呢? – 2012-01-08 01:09:04

+0

layout_centerInParent http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html – snowCrabs 2012-01-08 20:47:47