我有 2 张水平线性布局的图片。我要一个坐在左边,另一个坐在最右边。像这样
X-------------------------X
这是我的 XML
<LinearLayout
android:id="@+id/headerBarLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/batteryImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/battery" android:layout_weight="0"/>
<ImageView
android:id="@+id/exit_button"
style="@style/MotionMetrics.ExitButton"
android:src="@drawable/exit_button" android:layout_width="wrap_content"/>
</LinearLayout>
不确定为什么它们不在两端。
照片:
最佳答案
为此使用相对布局。像这样:
<RelativeLayout
android:id="@+id/headerBarLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/batteryImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/battery" android:layout_weight="0"
android:layout_alignParentLeft="true"
/>
<ImageView
android:id="@+id/exit_button"
style="@style/MotionMetrics.ExitButton"
android:src="@drawable/exit_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_gravity="right"
/>
</RelativeLayout>
关于java - 如何使用 LinearLayout 使两个图像位于两端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8002494/