Android 安卓怎么了:布局和重力?

Android 安卓怎么了:布局和重力?,android,android-layout,Android,Android Layout,我想知道安卓发生了什么:布局和重力。我的代码如下所示: <Button android:id="@+id/test_button" android:layout_width="250dp" android:layout_height="wrap_content" android:layout_gravity="center" android:text="test" android:textSize="25sp" /> 但是中心在按

我想知道安卓发生了什么:布局和重力。我的代码如下所示:

<Button
    android:id="@+id/test_button"
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="test"
    android:textSize="25sp" />


但是中心在按钮上什么都不做,eclipse甚至在下拉菜单上都没有。现在是他们的另一种方式吗?

您使用的是什么布局?如果您的按钮处于相对位置,这可能是您的问题。您可以使用LinearLayout,并使用布局和重力。或者在RelativeLayout中,您可以根据需要对齐视图。


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<Button
    android:id="@+id/test_button"
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="test"
    android:textSize="25sp" />

</LinearLayout?

尝试清理你的项目<代码>项目->清洁
。哦,我忘了线性布局了,谢谢~
<Button
    android:id="@+id/test_button"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="test"
    android:textSize="25sp" />