开发者

Issue with button text shifting

I'm having this odd issue. I have these buttons where the button's text is shifted downward upon certain actions. For example, I have a spinner with choices and one of the choices makes some buttons invisible while others are made visible. When I choose these, the buttons made visible all have their text shifted downward. Nothing else is shifted, just the text on the buttons. I've tried this on 1.5 and it works fine, no text is shifted, but I have issues with 2.1 and I really cannot figure it out. Any ideas or help would be great. Thanks.

Here is the xml of the file:

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

When i use the testprac spinner, the replay, new and submit buttons go invisible and the p开发者_JAVA百科lay button becomes visible (which is what I want). This seems to be when the issue seems to start. The play button's text is completely gone (probably shifted to low to see) and when I go back to the other button's are visible I get the issue that is shown below. The left is the issue before using the spinner, and the right is the issue. I don't know if it is just the spinner that causes this.

Issue with button text shifting

Issue with button text shifting


I think there is a bug when using Spinners inside RelativeLayout. If you try to change your root layout to a LinearLayout you2ll see it works as expected.

Changes on your original layout:

  1. root layout changed to LinearLayout.
  2. a dummy view added between TableLayouts to seperate them top and bottom.

Note: I found your question while trying to solve this. Seems similar.

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


The text is shifted inside the button? Could be a bug. Have you tried it on Android 2.2?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜