我正在使用线性布局来显示相当浅的初始屏幕。它有1个按钮,应该在屏幕的中心水平和垂直居中。然而无论我尝试按钮将顶部对齐中心。我已经包含了下面的XML,可以让我指出正确的方向吗?在线性布局中居中按钮
感谢
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageButton android:id="@+id/btnFindMe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:background="@drawable/findme"></ImageButton>
</LinearLayout>
什么用水平对齐方式的LinearLayout固定对我来说是设置'layout_width'为 “WRAP_CONTENT”。随后'layout_gravity'做了它应该做的事! – 2012-11-28 00:53:31
如果您严格需要使用LinearLayout,我认为这应该可以工作:http://stackoverflow.com/questions/18051472/how-to-center-the-content-inside-a-linear-layout – Antonio 2015-05-26 15:11:16