1

どんなに頑張っても一番下のボタンが見えません。上部に TextView があり、その下に 6 つのボタンがあるはずです。しかし、どういうわけか、私はそれらを見ることができません。私はここここを見ましたが、助けにはなりませんでした。教えてください、何が問題なのですか?これが私のレイアウトです:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="23dp"
        android:layout_marginTop="17dp"
        android:text="TextView" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_marginLeft="74dp"
        android:layout_marginTop="64dp"
        android:layout_toRightOf="@+id/textView1"
        android:text="@string/bttn_aux1"
        android:onClick="is_clicked" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button1"
        android:layout_below="@+id/button1"
        android:text="@string/bttn_aux2"
        android:onClick="can_clicked" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button2"
        android:layout_below="@+id/button2"
        android:text="@string/bttn_aux3"
        android:onClick="must_clicked" />

    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/button3"
        android:layout_below="@+id/button3"
        android:text="@string/bttn_aux4"
        android:onClick="do_clicked" />

    <Button
        android:id="@+id/button5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button4"
        android:layout_below="@+id/button4"
        android:text="@string/bttn_aux5"
        android:onClick="will_clicked" />

    <Button
        android:id="@+id/button6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/button5"
        android:layout_below="@+id/button5"
        android:text="@string/bttn_aux6"
        android:onClick="has_clicked" />

</RelativeLayout>

編集:これも私の活動です:

public class AuxilaryVerbs extends Activity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_auxilary);

        Intent intent = getIntent();
        String message = intent.getStringExtra(MainActivity.EXTRAMESSAGE_MAIN);

        TextView textView = new TextView(this);
        textView.setTextSize(30);
        textView.setText(message);

        setContentView(textView);
    }

    public void is_clicked(View view)   {


    }
    public void can_clicked(View view)  {


    }
    public void must_clicked(View view) {


    }
    public void do_clicked(View view)   {


    }
    public void will_clicked(View view) {


    }
    public void has_clicked(View view)  {


    }
}
4

2 に答える 2

4

Eclipse の自動 xml ジェネレーターは、必要のない余分な属性を大量に追加し、手動で編集しようとすると迷子になります。

まず RelativeLaout を LinearLayout に置き換えて垂直にすると、よりシンプルになります。次に、すべての layout_toRightOf、left、below などの属性を削除して、シンプルにします。次に、すべてのボタンが表示されます。ただし、デバイスにすべてを表示するのに十分なスペースがない場合は、ScrollView にボタンを配置して、スクロールしてすべてのボタンを取得できるようにする必要があります。

xmlを更新しようとしました(タイプミスがある可能性があります)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="23dp"
        android:layout_marginTop="17dp"
        android:text="TextView" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="74dp"
        android:layout_marginTop="64dp"
        android:text="@string/bttn_aux1"
        android:onClick="is_clicked" />

    <Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/bttn_aux2"
        android:onClick="can_clicked" />

    <Button
        android:id="@+id/button3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/bttn_aux3"
        android:onClick="must_clicked" />

    <Button
        android:id="@+id/button4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/bttn_aux4"
        android:onClick="do_clicked" />

    <Button
        android:id="@+id/button5"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/bttn_aux5"
        android:onClick="will_clicked" />

    <Button
        android:id="@+id/button6"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/bttn_aux6"
        android:onClick="has_clicked" />

</LinearLayout>

編集 これを削除します。このtextViewだけでビュー全体を設定しています。ビューは既に設定されています。

 setContentView(textView);

次の行を使用して、既にレイアウトを設定しています。もう上書きしてはいけません。

setContentView(R.layout.activity_auxilary);

レイアウト ファイルで ContentView を設定すると、テキストビューが既に存在します。次の行を使用してアクセスできます。

TextView textView = (TextView) v.findViewById(R.id.textView1); // id of textview from layoutfile

ビューを上書きしないでください。

于 2013-04-24T00:02:18.387 に答える
0

以前に宣言された ID への参照が正しくありません。

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView1" <---no plus sign; "@id/textView1"
    android:layout_marginLeft="74dp"
    android:layout_marginTop="64dp"
    android:layout_toRightOf="@+id/textView1" <---no plus sign;
    android:text="@string/bttn_aux1"
    android:onClick="is_clicked" />

次のフィールドで同じ問題が発生しています。

id を宣言するように、初めて id を割り当てる場合にのみプラス記号を使用します。ID が既に宣言されている場合は、プラス記号を使用する必要はありません。

于 2013-04-23T23:32:12.020 に答える