Android 我改变了重力,但按钮的位置是一样的
你能解释一下为什么当我改变重力时它没有改变吗。首先,当我改变它的位置按钮被改变,但现在我不能改变位置 main.XMLAndroid 我改变了重力,但按钮的位置是一样的,android,android-layout,Android,Android Layout,你能解释一下为什么当我改变重力时它没有改变吗。首先,当我改变它的位置按钮被改变,但现在我不能改变位置 main.XML <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wr
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="92dp"
android:layout_height="0dp"
android:layout_gravity="right"
android:layout_weight="1"
android:text="@string/button1" />
</LinearLayout>
为相关布局设置此属性android:layout\u width=“match\u parent”用于线性布局
(父布局)我猜您需要设置父布局(即包含按钮的线性布局)的属性“布局宽度”来填充父布局。您正在设置按钮的重力,这将导致设置视图的布局。例如,如果按钮上有文字,并且设置了重心,则它会将文字居中对齐到按钮中,若要将组件的重力设置到其父组件中,则需要设置父组件的重力 因此,请将代码更改为:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="92dp"
android:layout_height="0dp"
android:layout_weight="1"
android:text="@string/button1" />
</LinearLayout>
poste一些代码这对repley是有帮助的……为什么当我从图形布局中更改它时,它没有自动更改?