2010-06-08 128 views
1

我有這個奇怪的問題。我有這些按鈕的按鈕的文本在某些行動下向下移動。例如,我有一個微調選項,其中一個選項使一些按鈕不可見,而另一些則可見。當我選擇這些時,所有可見的按鈕的文本都向下移動。沒有別的東西被移動,只是按鈕上的文字。我已經在1.5上試了這個,它工作正常,沒有文字轉移,但我有2.1的問題,我真的不知道。任何想法或幫助都會很棒。謝謝。按鈕文字移位問題

下面是該文件的XML:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 


<TableLayout android:id="@+id/testpracHeader" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true"> 
    <!-- android:background="#ff0000"--> 

    <TableRow> 
     <Spinner android:id="@+id/testprac_menu" 
      android:layout_width="200px" 
      android:layout_height="wrap_content"></Spinner> 
     <View android:id="@+id/header_space_buffer" 
      android:layout_width="40px" 
      android:layout_height="30px" 
      android:gravity="center"></View> 
     <Button android:text="New" 
      android:id="@+id/newInterval" 
      android:layout_width="80px" 
      android:layout_height="wrap_content"></Button> 
    </TableRow> 
</TableLayout> 

<TableLayout android:id="@+id/bottomStruct" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true"> 
    <TableRow> 
     <Button android:layout_width="80px" 
      android:text="Replay" 
      android:id="@+id/replay" 
      android:layout_height="wrap_content"></Button> 
     <Button android:id="@+id/playInterval" 
      android:text="Play" 
      android:layout_width="160px" 
      android:layout_height="wrap_content"></Button> 
     <Button android:text="Submit" 
      android:id="@+id/submit" 
      android:layout_width="80px" 
      android:layout_height="wrap_content"></Button> 
    </TableRow> 
</TableLayout> 

</RelativeLayout> 

當我使用testprac微調,重播,新提交按鈕進入隱身和播放按鈕變得可見(這是我想要的)。這似乎是問題似乎開始的時候。播放按鈕的文本完全消失了(可能轉移到低位看),當我回到其他按鈕的可見時,我會看到下面顯示的問題。左邊是使用微調器之前的問題,右邊是問題。我不知道這是否只是微調造成的。

The GUI before I invoke the spinner The GUI after I invoke the spinner

+0

您需要發佈可疑XML。 – 2010-06-08 05:51:11

回答

0

我認爲在RelativeLayout中使用Spinner時存在一個錯誤。如果您嘗試將您的根目錄佈局更改爲LinearLayout,您會發現它按預期工作。

變化對您的原始佈局:

  1. 根佈局更改爲LinearLayout中。
  2. TableLayout s之間添加了一個虛擬視圖,以便將它們分開,並將其分別放置在頂部和 底部。

注:我發現你的問題,而試圖解決this。似乎相似。

<?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"> 


<TableLayout android:id="@+id/testpracHeader" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <!-- android:background="#ff0000"--> 

    <TableRow> 
     <Spinner android:id="@+id/testprac_menu" 
      android:layout_width="200px" 
      android:layout_height="wrap_content"></Spinner> 
     <View android:id="@+id/header_space_buffer" 
      android:layout_width="40px" 
      android:layout_height="30px" 
      android:gravity="center"></View> 
     <Button android:text="New" 
      android:id="@+id/newInterval" 
      android:layout_width="80px" 
      android:layout_height="wrap_content"></Button> 
    </TableRow> 
</TableLayout> 

<View 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"/> 

<TableLayout android:id="@+id/bottomStruct" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
    <TableRow> 
     <Button android:layout_width="80px" 
      android:text="Replay" 
      android:id="@+id/replay" 
      android:layout_height="wrap_content"></Button> 
     <Button android:id="@+id/playInterval" 
      android:text="Play" 
      android:layout_width="160px" 
      android:layout_height="wrap_content"></Button> 
     <Button android:text="Submit" 
      android:id="@+id/submit" 
      android:layout_width="80px" 
      android:layout_height="wrap_content"></Button> 
    </TableRow> 
</TableLayout> 

</LinearLayout> 
0

文本轉移按鈕?可能是一個錯誤。你在Android 2.2上試過了嗎?

+0

是的,它在按鈕內移動。該按鈕的位置和其他一切都還好。我將不得不在2.2版本上嘗試。我會看看我能否提供照片。 – Fizz 2010-06-08 14:32:48

+0

setVisibility()是您調用這些按鈕的唯一方法嗎?你用View.GONE而不是View.INVISIBLE試過嗎?這個方向是否依賴? – Shade 2010-06-09 13:26:33

+0

View.GONE並不完全是我想要的。雖然,我確實將按鈕移動了很多(比圖片中顯示的要多),但他們不再有這個問題了。問題可能是因爲命令android:layout_alignParentBottom的錯誤? – Fizz 2010-06-09 14:58:13