开发者

layout messed up once spinner has entries

开发者 https://www.devze.com 2023-02-02 08:47 出处:网络
I have <LinearLayout xmlns开发者_如何学Go:android=\"http://schemas.android.com/apk/res/android\"

I have

<LinearLayout xmlns开发者_如何学Go:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/LinearLayoutPlayer"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <Spinner 
            android:id="@+id/Spinner01"
            android:layout_width="fill_parent"  
            android:layout_height="wrap_content"
            android:layout_weight="100" />

        <ToggleButton 
            android:text="@+id/ToggleButton01"
            android:id="@+id/ToggleButton01" 
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_weight="1" />
</LinearLayout>

Which displays a spinner and a next to its a ToggleButton. Everything okay so far. Of course the spinner need some entries, so I add to the spinner the attribute:

android:entries="@array/myentries"

The problem now is that the ToggleButton is a bit lower than the spinner and the button of the ToggleButton is cut off, maybe 3 or 5 lines of pixels.

Anyone an idea what is wrong here? Android is version 2.2

Thanks!


Try wrapping your ToggleButton in a new LinearLayout. Your xml would then be:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayoutPlayer"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <Spinner 
        android:id="@+id/Spinner01"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:entries="@array/planets_array"
        android:layout_weight="100">
    </Spinner>
    <LinearLayout 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >
        <ToggleButton
            android:text="@+id/ToggleButton01"
            android:id="@+id/ToggleButton01" 
            android:layout_height="wrap_content"
            android:layout_width="wrap_content" 
            android:layout_weight="1">
        </ToggleButton>
    </LinearLayout>
</LinearLayout>
0

精彩评论

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

关注公众号