Android 相对布局不符合定义
下面是我的布局XML代码Android 相对布局不符合定义,android,android-layout,Android,Android Layout,下面是我的布局XML代码 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:id="@+id/RelativeLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/default1"
android:id="@+id/default1"
android:layout_gravity="center"
android:scaleType="fitXY">
</ImageView>
<ImageView
android:layout_marginTop="19dp"
android:layout_width="180dp"
android:layout_height="45dp"
android:src="@drawable/fc_postyour_best_score_bg"
android:id="@+id/postscore"
android:layout_alignParentRight="true"
android:scaleType="fitXY">
</ImageView>
<ImageButton
android:layout_marginTop="22dp"
android:layout_width="35dp"
android:layout_height="35dp"
android:background="@drawable/fctwitterup"
android:layout_marginLeft="7dp"
android:id="@+id/twitter"
android:layout_alignRight="@id/postscore"
android:scaleType="fitXY">
</ImageButton>
<ImageButton
android:layout_marginTop="22dp"
android:layout_width="35dp"
android:layout_height="35dp"
android:background="@drawable/fcfacebookdown"
android:id="@+id/fb"
android:layout_toLeftOf="@id/twitter">
</ImageButton>
<ImageButton
android:layout_width="160dp"
android:layout_height="40dp"
android:background="@drawable/fsremove_ads_down"
android:id="@+id/fsremove_ads_down"
android:layout_below="@id/postscore"
android:layout_alignParentRight="true"
android:layout_marginBottom="3dp">
</ImageButton>
<ToggleButton
android:id="@+id/fsvibrate_on"
android:layout_width="135dip"
android:layout_height="35dip"
android:textOff=""
android:textOn=""
android:layout_below="@+id/fsremove_ads_down"
android:layout_alignParentRight="true"
android:background="@drawable/fsvibrate_on">
</ToggleButton>
<ImageButton
android:layout_width="210dp"
android:layout_height="60dp"
android:background="@drawable/fcplaydown"
android:id="@+id/fcplaydown"
android:layout_centerInParent="true">
</ImageButton>
<ToggleButton
android:id="@+id/fcsoundondown"
android:layout_width="35dp"
android:layout_height="35dp"
android:textOff=""
android:textOn=""
android:layout_below="@+id/fcplaydown"
android:background="@drawable/fcsoundondown">
</ToggleButton>
</RelativeLayout>
</LinearLayout>
因此,我的问题是
@+id/fcsoundondown
切换按钮,我已将其设置为@+id/fcplaydown
的下方,但它不是位于指定按钮的下方,而是位于“@+id/postscore”之后@+id仅在为元素分配新id时才应使用。引用元素时,请使用@id
字符串开头的at符号(@)表示XML解析器应该解析和展开ID字符串的其余部分,并将其标识为ID资源。加号(+)表示这是一个新的资源名称,必须创建并添加到资源中(在R.java文件中)
参考资料:我不知道如何解释为什么会发生这种情况,但这与您将@+id/fcplaydown ImageButton
设置为在父对象中居中有关,而他的父对象是具有换行符内容宽度和高度的相对对象,因此布局会变得混乱
因此,将RelativeLayout
设置更改为match\u parent
,它就会工作
<RelativeLayout
android:id="@+id/RelativeLayout01"
android:layout_height="match_parent"
android:layout_width="match_parent">
布局视图id用于关联位置和尺寸。现在,当一个id被定义时,它被存储在R.java中。我们都知道这一点。我们不知道的是,RelativeLayout中的视图是由布局文件的多个解析构建的。考虑到编译是一个昂贵的过程,并且需要在这个过程上进行优化,当你想使用Android时,它需要使用+号重置id,而不仅仅是在你声明它时。尽管有点让人困惑,这就是它的使用方法。你能分享一个屏幕截图来说明你的问题吗?好的,好的,我已经改变了,但我的问题仍然存在,请给我一些技巧。谢谢,这是有效的,但现在我想在@+id/fcsoundondown的右侧放置一个按钮,但它似乎位于屏幕顶部,你能指导我吗???android:layout_-toRightOf只是将其位置设置为水平,您还必须添加另一个属性以将其位置设置为垂直,可能是android:layout_-alignTop=“@id/fcsoundondown”或android:layout_-alignBottom=“@id/fcsoundondown”,或两者,具体取决于您的偏好