【发布时间】:2016-01-25 22:14:12
【问题描述】:
我有一个RelativeLayout 居中我有一个ImageButton 居中。我想要另一个在第一个的右侧,但它显示在屏幕左侧,虽然与顶部对齐。
我使用了相对布局,因为我希望按钮彼此相对。 (这是错的吗?)
我总共有四个按钮。
#1 centered.
#2 to the right of #1
#3 above #2
#4 to the left of #3
像这样
.................
. .
. 43 .
. 12 .
. .
.................
#1 位于中间。目前它看起来像这样:
.................
. .
.43 .
. 2 1 .
. .
.................
- 我做错了什么?
这是布局文件:
<RelativeLayout
android:id="@+id/board_id"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg480x800"
android:orientation="vertical"
android:padding="0dp" >
<Button
android:id="@+id/game_choice_6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/game_choice_4" />
<Button
android:id="@+id/game_choice_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/game_choice_1" />
<Button
android:id="@+id/game_choice_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/game_choice_2" />
<Button
android:id="@+id/game_choice_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/game_choice_3" />
<Button
android:id="@+id/game_choice_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/square_layout_id"
android:layout_centerVertical="true" />
<Button
android:id="@+id/game_choice_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/square_layout_id" />
<com.brdgms.android.SquareLayout
android:id="@+id/square_layout_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#00000000" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/game_board"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="game Board"
android:src="@drawable/game_board" />
<com.brdgms.android.games.game.GameBoardView
android:id="@+id/game_canvas"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ImageButton
android:id="@+id/button_game_player_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/game_player_1_button" />
<ImageButton
android:id="@+id/button_game_player_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/button_game_player_1"
android:layout_toRightOf="@+id/button_game_player_1"
android:layout_toEndOf="@+id/button_game_player_1"
android:src="@drawable/game_player_2_button" />
<ImageButton
android:id="@+id/button_game_player_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button_game_player_2"
android:layout_alignLeft="@+id/button_game_player_2"
android:src="@drawable/game_player_3_button" />
<ImageButton
android:id="@+id/button_game_player_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/button_game_player_3"
android:layout_toLeftOf="@+id/button_game_player_3"
android:src="@drawable/game_player_4_button" />
</RelativeLayout>
</com.brdgms.android.SquareLayout>
</RelativeLayout>
【问题讨论】:
标签: android android-relativelayout