Android 为什么按钮3不';设置布局“U重力=”后不移动;对吧;?
下面是我的Activity.xml文件。我已经设置了按钮布局,\u gravity=“right”,但它不起作用,有人能告诉我为什么吗?谢谢Android 为什么按钮3不';设置布局“U重力=”后不移动;对吧;?,android,Android,下面是我的Activity.xml文件。我已经设置了按钮布局,\u gravity=“right”,但它不起作用,有人能告诉我为什么吗?谢谢 <LinearLayout xmlns:android=" http://schemas.android.com/apk/res/android" xmlns:tools=" http://schemas.android.com/tools" android:layout_width="match_parent" android:layo
<LinearLayout xmlns:android=" http://schemas.android.com/apk/res/android"
xmlns:tools=" http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="303dp"
android:layout_height="wrap_content"
android:layout_weight="0.99"
android:src="@drawable/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="0.99"
android:baselineAligned="_baseline"
android:orientation="horizontal" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Button" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
这是不应该的,这就是为什么 只有当布局垂直时,才会考虑右布局\重力,在这种情况下,它将产生预期的结果 对于您尝试执行的操作,请在第二个按钮和第三个按钮之间使用间隔符,如下所示:
<View android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
它会填满空间并向右按按钮。这是不应该的,这就是为什么 只有当布局垂直时,才会考虑右布局\重力,在这种情况下,它将产生预期的结果 对于您尝试执行的操作,请在第二个按钮和第三个按钮之间使用间隔符,如下所示:
<View android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
它将填充空间并向右按按钮。尝试将版面宽度设置为0dptry将版面宽度设置为0dpnota:从android 14开始,有一个空格小部件。我不认为它能做得更多,但至少它的名字说明了它能做什么。我已经改变了设计,但我会尝试一下。注:从安卓14开始,有一个空间小部件。我不认为它做得更多,但至少它的名字说明了它的功能。我已经改变了设计,但我会尝试一下。