我正在尝试构建一个 UI 屏幕。 这是 main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.33"
android:orientation="horizontal" >
<ImageView
android:id="@+id/kartoMap"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_gravity="left"
android:src="@drawable/ic_launcher" />
<VideoView
android:id="@+id/robotVideo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="right"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.66"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.2"
android:orientation="vertical" >
<ToggleButton
android:id="@+id/stepsBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="1"
android:text="Steps"
android:textOff="STEPS"
android:textOn="STEPS" />
<Button
android:id="@+id/ArmsBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Arms HOLDER" />
</LinearLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:id="@+id/joystickRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:src="@drawable/joystick" />
<ImageView
android:id="@+id/innerCircle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/inner_circle" />
</FrameLayout>
</LinearLayout>
</LinearLayout>
问题出在名为“joystickRight”的 ImageView 中。 我希望它被绑定(bind)到屏幕的右侧,但是 - FrameLayout 和 LinearLayout 被划分在下屏幕,imageView 位于 FrameLayout 的中心。为什么??
最佳答案
因为FrameLayout的高度和宽度都设置为wrap_content。因此它在 FrameLayout 内部对齐,而 FrameLayout 仅与 ImageView 一样宽。
执行此操作FrameLayout android:layout_width="fill_parent"
关于Android UI重力="right"不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11074290/