1

トグルボタンでアクティビティを作成しました。クリックを処理するコードも作成しました。

しかし、アプリを実行すると、アクティビティ画面にトグルボタンが表示されません。

エミュレーターに問題があるのではないかと思ったので、エクスポートして携帯電話で試してみました。

しかし、それは電話にも表示されません。

アクティビティレイアウトファイルの説明は次のとおりです。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <Button
        android:id="@+id/btnStartService"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="Start Notifying" />

    <EditText
        android:id="@+id/txtUserMsg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/btnStartService"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="82dp"
        android:ems="10"
        android:inputType="textMultiLine" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/txtWelcomeMsg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="18dp"
        android:text="TextView" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/txtUserMsg"
        android:layout_centerHorizontal="true"
        android:text="Message to reply with" />

    <Button
        android:id="@+id/stopNotifying"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/btnStartService"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="40dp"
        android:text="Stop Notifying" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/btnStartService"
        android:layout_alignLeft="@+id/txtUserMsg"
        android:layout_marginBottom="29dp"
        android:text="Caller Notifications" />

    <ToggleButton
        android:id="@+id/tglStartStop"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView2"
        android:layout_alignBottom="@+id/textView2"
        android:layout_toRightOf="@+id/txtWelcomeMsg"
        android:text="ToggleButton"
        android:visibility="visible" />

</RelativeLayout>

なぜこれが起こるのか、何か考えはありますか?

4

2 に答える 2

1

通常、@+idはidフィールドでのみ使用します。それ以外の場合は、すべての割り当てに@idを使用します。ただし、これで問題が発生することはありません。トグルボタンを使用する場所にコードを投稿してください。

于 2012-10-02T17:44:57.947 に答える
1

コンセプトエラーがあると思います。他のウィジェットに関連するウィジェットを配置するときは、次のようにする必要があります。例:

android:layout_toRightOf="@id/txtWelcomeMsg"

それ以外の:

android:layout_toRightOf="@+id/txtWelcomeMsg"
于 2012-10-02T17:45:07.073 に答える