Android UI重力="right"不起作用

标签 android xml android-layout user-interface

我正在尝试构建一个 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/

相关文章:

xml - XSLT,如何获取和输出组合元素

android - 如何将定义的单选按钮布局分配给动态单选按钮

android - 需要在 、顶部和底部栏之间显示项目列表,

android - 如何自定义布局

具有不同主题的 Android 应用程序和 Actionbar

android - listview recyclerview 问题?

android - Auth0 与 Xamarin PCL 依赖服务 NullReferenceException

android - 我可以在 2.1 上编译 Android 应用程序并支持 1.5 及以上的所有版本吗?

android - 在 Android 中的 TabLayout 中向选项卡添加图标

javascript - (无限?)JavaScript 代码中的循环