我想知道android:layout_gravity发生了什么。我的代码如下所示:
<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甚至没有在他们的下拉菜单上。他们现在是另一种方式吗?
答案 0 :(得分:2)
<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?
android:layout_gravity位于LinearLayout.LayoutParams
所以,它适用于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" />
答案 1 :(得分:1)
您使用的是什么布局?如果您的按钮位于RelativeLayout中,则可能是您的问题。您可以使用LinearLayout,并使用layout_gravity。或者在RelativeLayout中,您可以根据需要对齐视图。