Android图形布局不显示切换按钮

Android图形布局不显示切换按钮,android,eclipse,togglebutton,graphical-layout-editor,Android,Eclipse,Togglebutton,Graphical Layout Editor,我是android编程新手,有个问题。我使用Eclipse并创建了一个切换按钮,但在图形布局中并没有显示任何内容,它向我显示了在渲染期间引发的异常:-1。我能做什么?我在下面张贴我使用过的代码 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:padding="25dp" android:layout_width="match_parent" android:layout_hei

我是android编程新手,有个问题。我使用Eclipse并创建了一个切换按钮,但在图形布局中并没有显示任何内容,它向我显示了在渲染期间引发的异常:-1。我能做什么?我在下面张贴我使用过的代码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="25dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<EditText
    android:id="@+id/etCommands"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="Type a Command"
    android:password="true" />

<LinearLayout
    android:weightSum="100"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <Button
        android:layout_weight="20"
        android:id="@+id/bResults"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="Try Command" />

    <ToggleButton
        android:layout_weight="80"
        android:paddingBottom="10dp"
        android:checked="true"
        android:id="@+id/tbPassword"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="ToggleButton" />
</LinearLayout>

<TextView
    android:id="@+id/tvResults"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="invalid" />

使用布局权重的推荐方法是将尺寸设置为0dp并设置所需的权重,这样android将调整其大小:

<ToggleButton
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="80"
    android:text="ToggleButton" />
我不认为这是它崩溃的原因,所以最好发布整个xml

--更新-----------------------

我没有得到任何渲染错误,但是由于按钮宽度设置为“填充父项”,您应该使用“匹配父项”,因为不推荐使用“填充父项”,并且在水平线性布局中有两个项目,第二个项目不可见

此外,当使用预期动态尺寸的重量时,请使用0dp

这是你的布局。我还交换了重量,这样你的纽扣看起来更好我想这是个错误

<?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:padding="25dp" >

<EditText
    android:id="@+id/etCommands"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Type a Command"
    android:password="true" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="100" >

    <Button
        android:id="@+id/bResults"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="80"
        android:text="Try Command" />

    <ToggleButton
        android:id="@+id/tbPassword"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="20"
        android:checked="true"
        android:paddingBottom="10dp"
        android:text="ToggleButton" />
</LinearLayout>

<TextView
    android:id="@+id/tvResults"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="invalid" />

您可以发布整个xml吗?感谢您的努力和时间,但我创建了一个纯/白色xml文件,并从图形布局中拖放切换按钮图标,它显示以下消息:渲染期间引发的异常:-1异常详细信息记录在窗口>显示视图>错误日志中图形预览布局编辑器可能不准确:Path.addRoundRect中不支持不同的角尺寸。忽略此会话是否在样式中定义自定义切换按钮?你在一个新的项目中尝试过这个布局吗?你说的custon切换按钮是什么意思?对不起,我是android新手,我不知道所有的意思。我在layout文件夹中创建了一个新的xml文件,然后我拖放了一个切换按钮,它出现在图形布局中的表单小部件中,然后弹出了上面的错误。您可以为视图定义样式,例如切换按钮,但如果您不知道,那么我肯定您不知道。您可以在图形编辑器中检查选择了哪个api,或者在新的空项目中尝试布局。在哪里可以检查选择了哪个api?