2011-07-05 55 views
7

现在,这里是布局我的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: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"

+0

你能分享一个截图来说明你的问题吗? – Udayan

回答

12

我不知道要很好地解释,为什么出现这种情况,但它关系到你的设置@+id/fcplaydown ImageButton父居中,和他的父母是与WRAP_CONTENT的宽度和高度,在一个RelativeLayout的布局只是感到困惑。

因此,将RelativeLayout设置更改为match_parent,它将起作用。

<RelativeLayout 
    android:id="@+id/RelativeLayout01" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent"> 
+0

感谢这个工程,但现在我想把一个按钮右侧@ + id/fcsoundondown,但它似乎在屏幕的顶部可以你引导我??? –

+0

\t \t

+0

安卓layout_toRightOf只设置水平的位置,你必须添加其他属性来设置它的垂直位置也说不定的机器人: layout_alignTop =“@ id/fcsoundondown”或android:layout_alignBottom =“@ id/fcsoundondown”,或两者兼有,具体取决于您的喜好 – Adinia

-1

@ + id只有在您为元素分配新ID时才应使用。而当你指的是一个元素使用@id

字符串开头的at符号(@)表示XML解析器应该解析并展开ID字符串的其余部分,并将其标识为ID资源。加号(+)表示这是一个新的资源名称,必须创建并添加到我们的资源中(在R.java文件中)。

参考:http://developer.android.com/guide/topics/ui/declaring-layout.html#id

+1

okk okkk我已经改变了,但我的问题仍然存在,请给出任何窍门 –

0

布局视图标识符用于关联位置和大小。现在,当一个id被定义时,它被存储在R.java中。我们都知道。那么,我们不知道的是,RelativeLayout中的视图是由多个布局文件的解析构建而成的。考虑到编译是一个昂贵的过程,并且需要优化此过程,所以Android需要使用+符号重置id,当您想使用它时,不仅在您声明它时。即使它有点混乱,这是如何被使用。