1

无论我尝试过,我都看不到底部的按钮。顶部应该有一个 TextView,下面应该有六个按钮。但不知何故,我看不到他们。我看过这里,也看过这里,但他们没有帮助。请告诉我,有什么问题?这是我的布局:

<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 auto xml generator adds a lot of extra attribute that you don't need and when you try to edit it manually you get lost.

First replace RelativeLaout to LinearLayout and make it vertical, it will make it simpler. Then remove all layout_toRightOf,left, below etc attribute and make it simple. Then you will see all your buttons. However if there isn't enough space to show all in your device then you will have to put button in ScrollView so you can scroll and get all buttons.

I tried to update xml (there could be some typos)

<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>

Edit Remove this. You are setting your whole view with just this textView. You have already set your view.

 setContentView(textView);

You have already set layout using following line. You shouldn't overwrite it again.

setContentView(R.layout.activity_auxilary);

You already have your textview when you setContentView with your layout file. You can get access to it using following line.

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

and that's it, don't overwrite view.

于 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 回答