2011-06-08 106 views
0

具有RelativeLayout的自定義Dialog框包含一個不會改變其邊距(無論方向如何)的Button小部件。這裏的XML:相對佈局中的按鈕不受設置版面邊距的影響


<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" android:layout_height="match_parent" 
    android:orientation="horizontal" android:background="#99000000"> 
    <TextView android:id="@+id/dialogtitle" android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:text="Some text" /> 
    <TextView android:id="@+id/dialogtext" android:layout_width="300dp" 
     android:layout_height="wrap_content" android:textSize="15dp" 
     android:layout_alignParentLeft="true" android:layout_below="@id/dialogtitle" 
     android:paddingLeft="8dp" /> 
    <Button android:id="@+id/dialogbuttoninfo" android:layout_width="80dp" 
     android:layout_height="wrap_content" android:text="Doesn't care about margins" 
     android:layout_alignParentRight="true" android:layout_marginLeft="128dp" /> 
</RelativeLayout> 

填充工程,但只移動按鈕內的文本。有什麼建議麼?

+1

你想做什麼?我可以添加一個右邊距並且它可以工作 – 2011-06-08 19:19:40

+0

它對於一個對話框,所以也許這也解釋了變異性 – 2011-06-09 00:30:05

+0

也是,'mumps'標籤到底是什麼? – 2011-06-09 03:30:07

回答

1

這似乎糟糕,但你試過把它所有的LinearLayout呢?或者可能刪除android:orientation="horizontal"。我不認爲RelativeLayout關心我所看到的方向。此外,我想,但可能是錯誤的,如果你做一個LinearLayout那麼你就不需要在那裏android:layout_alignParentLeft="true"無論是。

清理了一下之後(很遺憾,但是當它在問題中被壓縮時很難閱讀),你也沒有說明最後的TextView,dialogbuttoninfo應該是相對於其他任何東西,I認爲你必須爲Relative layouts這樣做才能正常行事,我已經發生了一些棘手的事情。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:background="#99000000"> 
    <TextView 
     android:id="@+id/dialogtitle" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Some text" /> 
    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal"> 
     <TextView 
      android:id="@+id/dialogtext" 
      android:layout_width="300dp" 
      android:layout_height="wrap_content" 
      android:textSize="15dp" 
      android:layout_alignParentLeft="true" 
      android:paddingLeft="8dp" /> 
     <Button 
      android:id="@+id/dialogbuttoninfo" 
      android:layout_width="80dp" 
      android:layout_height="wrap_content" 
      android:text="Doesn't care about margins" 
      android:layout_alignParentRight="true" 
      android:layout_marginLeft="128dp" /> 
    </LinearLayout> 
</LinearLayout> 
+0

好的名字。諷刺指出。我也在讀研究生。是的,Llayout的作品,也許我會用它。 Android UI工具讓我瘋狂。無論我做什麼,只要我開始在不同的設備上測試,我確信它會全部解開。哥們,謝啦。 – 2011-06-09 00:37:55

+0

哈哈你自己的名字。我也遇到了很多與佈局不一致的挫折,幸運的是,android和java似乎總是有另一種方式來完成任何事情。 – 2011-06-09 00:55:05

+0

IMO最好的方法是在glsurfaceview中使用opengl。它基本上是一個空白的畫布,沒有任何限制,幾乎沒有'android'。 – 2011-06-09 01:14:00

1

您可能需要將按鈕的左邊緣與邊緣對齊之前的內容對齊,纔有真正的意義。

相關問題