2012-04-16 105 views
0

我有我認爲是一個簡單的佈局。這包含一個滾動視圖,在這個水平滾動視圖中,所以我可以滾動雙向。我簡化了這個例子,所以它有一個包含一個TextView和另一個RelativeLayout的RelativeLayout。下面是XML: RelativeLayout不顯示項目左邊

<HorizontalScrollView 
     android:id="@+id/scrollView" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:fadeScrollbars="false" 
     android:scrollbarAlwaysDrawHorizontalTrack="true" 
     android:fillViewport="true"> 
     <RelativeLayout 
      android:id="@+id/mainLayout" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent"     
      android:orientation="horizontal" > 
      <TextView 
       android:id="@+id/myText" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"      
       android:text="TEXT LABEL" /> 
      <RelativeLayout 
       android:id="@+id/relativeLayout" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/myText"> 
        <Button android:id="@+id/button2" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_toLeftOf="@+id/button1" 
         android:layout_above="@+id/button1" 
         android:text="2"/> 
        <Button android:id="@+id/button1" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="1"/> 
        <Button android:id="@+id/button3" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_below="@+id/button1" 
         android:text="3"/>      
      </RelativeLayout> 
     </RelativeLayout> 
    </HorizontalScrollView> 
</ScrollView> 

我可以看到按鈕1和3,但我沒有看到按鈕2.我需要做這樣不幸的是,因爲頁面是動態生成的(這個XML是一種簡化我正在做的版本),我只知道我需要留下什麼。我曾經在一點工作,但不得不重新安排一些其他的代碼,並打破了。我錯過了什麼?

下面是一個快照的鏈接:snapshot

+0

你可以發佈一個鏈接到它現在的樣子嗎? – FoamyGuy 2012-04-16 19:56:42

+0

按鈕2應該放在哪裏? – 207 2012-04-16 20:24:06

+0

button2應該與button1的左上角對齊。我知道我可以將button1與button2的右下角對齊,但我需要以這種方式構建它。 – 2012-04-16 21:00:53

回答

0

BUTTON2是關閉屏幕Button1的左上角。

我不確定你的預期結果是什麼,但是你可以嘗試將button2錨定到左上角(layout_alignParentTop,layout_alignParentLeft),然後根據你想要的顯示button1到右邊或下面。

下面是這樣一個例子,如果你只是想Button1以BUTTON2權:

  <Button 
       android:id="@+id/button2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="2" 
       android:layout_alignParentLeft="true" /> 

      <Button 
       android:layout_toRightOf="@+id/button2" 
       android:id="@+id/button1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="1" /> 

      <Button 
       android:id="@+id/button3" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/button1" 
       android:text="3" /> 
     </RelativeLayout> 

取決於你實際上是試圖做(我糊塗了由Android:layout_above =「@ + id/button1」AND android:layout_toLeftOf =「@ + id/button1」in button2)

+0

上面的和toLeftOf會將button2放在button1的左上角。 – 2012-04-16 20:59:18