问题
I am building a app. At the moment I am just building a test UI so I can show off the functionality of the app. I ran across a problem where I want to have three ToggleButtons displayed in a horizontal fashion. So I did this using a Linear view. How ever the buttons are distorted looking. Here is a picture of the distortion:
private ToggleButton wifiTB;
private ToggleButton gpsTB;
private ToggleButton bluetoothTB;
Called in onCreate()
wifiTB = (ToggleButton)this.findViewById(R.id.WifiTB);
gpsTB = (ToggleButton)this.findViewById(R.id.GPSTB);
bluetoothTB = (ToggleButton)this.findViewById(R.id.bluetoothTB);
Layout xml:
<LinearLayout android:id="@+id/linearLayout1"
android:layout_height="wrap_content" android:layout_width="match_parent"
android:gravity="center">
<ToggleButton android:id="@+id/WifiTB" android:textOn="Wifi"
android:textOff="Wifi" android:layout_weight="1"
android:layout_width="wrap_content" android:layout_height="wrap_content"></ToggleButton>
<ToggleButton android:layout_width="wrap_content"
android:id="@+id/GPSTB" android:textOn="GPS" android:textOff="GPS"
android:layout_weight="1" android:layout_height="wrap_content"></ToggleButton>
<ToggleButton android:layout_height="wrap_content"
android:layout_width="wrap_content" android:id="@+id/bluetoothTB"
android:textOn="Bluetooth" android:textOff="Bluetooth"
android:layout_weight="1"></ToggleButton>
</LinearLayout>
Note: - I tried removing a button for the linear view and replacing it instead below the close button. - I tried placing it in a RelativeLayout instead of LinearLayout. - Playing with the width and height of the layout/buttons.
来源:https://stackoverflow.com/questions/6583531/android-toggle-button-distorted-view