2

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 にあります。画面の右側に結び付けたいのですが、代わりに、frameLayoutとlinearLayoutが画面下で分割され、imageViewがframeLayoutの中央にとどまります。どうして??

4

4 に答える 4

2

左に表示する要素と右に表示する要素の間に、水平 LinearLayout 内に空のビューを追加してみてください。

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <View
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="1"
            />                

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>
于 2013-02-03T22:53:22.023 に答える
2

FrameLayout は高さと幅の両方で wrap_content に設定されているためです。そのため、画像ビューと同じ幅しかない FrameLayout の内側に配置されています。

これを行うFrameLayout android:layout_width="fill_parent"

于 2012-06-17T20:00:36.987 に答える
1

RelativeLayout代わりにa を使用FrameLayoutしてから、joystickRight のオプションを使用しないのはなぜですかandroid:layout_alignParentRight="true"

于 2012-06-17T19:55:19.907 に答える
0

`android:layout_gravity =" right "を使用する必要があります。そうすると、ビューは親内で右に配置されます。

または、Phobosが提案したように実行し、ビューの幅を「match_parent」にandroid:gravityすると、期待どおりに機能します。

于 2012-06-17T21:17:33.107 に答える