Android 相对位置问题
我有一个Android 相对位置问题,android,android-layout,android-relativelayout,Android,Android Layout,Android Relativelayout,我有一个布局,其中包含4个水平线性布局,每个布局内有3个图像按钮 现在我想将那些LinearLayout转换为RelativeLayout,因为我需要添加更多元素,并且我必须使用toRightOf,alignParentTop等 以下是我用来进行此更改的代码: <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/andro
布局
,其中包含4个水平线性布局
,每个布局内有3个图像按钮
现在我想将那些LinearLayout
转换为RelativeLayout
,因为我需要添加更多元素,并且我必须使用toRightOf
,alignParentTop
等
以下是我用来进行此更改的代码:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/bugbox_wall_port" >
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
<Button
android:id="@+id/writeNewMsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="New" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp" >
<ImageButton
android:id="@+id/spyMsgs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/msgspy" />
<ImageButton
android:id="@+id/playerMsgs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/msgplyr"
android:layout_toRightOf="@id/spyMsgs" />
<ImageButton
android:id="@+id/allyMsgs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/msgally"
android:layout_toRightOf="@id/playerMsgs" />
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp" >
<ImageButton
android:id="@+id/battleMsgs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/msgbatt" />
<ImageButton
android:id="@+id/skynetMsgs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/msgnet" />
<ImageButton
android:id="@+id/transportMsgs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/msgtrans" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp" >
<ImageButton
android:id="@+id/expeditionMsgs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/msgexp" />
<ImageButton
android:id="@+id/newsMsgs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/msgnews" />
<ImageButton
android:id="@+id/buildingMsgs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/msgbuild" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp" >
<ImageButton
android:id="@+id/allMsgs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/msgall" />
<ImageButton
android:id="@+id/binMsgs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="@drawable/msgbin" />
</LinearLayout>
</LinearLayout>
</ScrollView>
但是我不知道为什么,RelativeLayout
有问题
下面是一张图片,我以图形方式解释了我的问题:
它快把我逼疯了。我不知道为什么会这样。我以前使用过RelativesLayout,它们没有问题
所以我的问题是:为什么会发生这种情况?那么我该如何修复这个错误呢
提前谢谢你 试试这个。我注释掉了底部的线性布局。如果相对布局按您希望的方式工作,则可以相应地调整其他直线
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:background="@drawable/bugbox_wall_port" >
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
<Button
android:id="@+id/writeNewMsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="New" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp" >
<ImageButton
android:id="@+id/spyMsgs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_launcher" />
<ImageButton
android:id="@+id/playerMsgs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/ic_launcher"
android:layout_toRightOf="@id/spyMsgs" />
<ImageButton
android:id="@+id/allyMsgs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_launcher"
android:layout_toRightOf="@id/playerMsgs" />
</RelativeLayout>
<!-- <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp" >
<ImageButton
android:id="@+id/battleMsgs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/msgbatt" />
<ImageButton
android:id="@+id/skynetMsgs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/msgnet" />
<ImageButton
android:id="@+id/transportMsgs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/msgtrans" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp" >
<ImageButton
android:id="@+id/expeditionMsgs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/msgexp" />
<ImageButton
android:id="@+id/newsMsgs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/msgnews" />
<ImageButton
android:id="@+id/buildingMsgs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/msgbuild" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp" >
<ImageButton
android:id="@+id/allMsgs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/msgall" />
<ImageButton
android:id="@+id/binMsgs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="@drawable/msgbin" />
</LinearLayout> -->
</LinearLayout>
</ScrollView>
已解决。我正在按程序设置视图的ID,但我没有意识到…您是否已经发布了相同的问题?