找不到“注册”按钮了

时间:2014-08-14 07:30:11

标签: android android-layout android-xml

我正在开发一个Android应用程序,我遇到了一个小问题

这是注册XML文件

<?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:background="@drawable/ic_signup"
    android:gravity="center_vertical"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/editTextEmail"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="Email" />

    <requestFocus />

    <EditText
        android:id="@+id/editTextFirstName"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="First Name" />

    <EditText
        android:id="@+id/editTextLastName"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="Last Name" />

    <EditText
        android:id="@+id/editTextPassword"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="Password"
        android:inputType="textPassword" />

    <EditText
        android:id="@+id/editTextConfirmPassword"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="Confirm Password"
        android:inputType="textPassword" />

    <EditText
        android:id="@+id/editTextAge"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="Age" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_horizontal"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/mynumber"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Number +961"
            android:textSize="20sp"
            android:color="@color/black" />

        <EditText
            android:id="@+id/editTextNumber"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="Number" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/ic_signup"
            android:gravity="center_vertical"
            android:orientation="vertical" >

            <Button
                android:id="@+id/buttonCreateAccount"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_marginBottom="60dp"
                android:background="@color/androidwhite"
                android:text="Create Account" />

        </LinearLayout>
    </LinearLayout>
</LinearLayout>

这是注册活动的onCreate()方法

super.onCreate(savedInstanceState);
setContentView(R.layout.signup);

// Get instance of the database adapter
loginDataBaseAdapter = new LoginDataBaseAdapter(this);
loginDataBaseAdapter = loginDataBaseAdapter.open();

// Get references of views
mynumber = (TextView) findViewById(R.id.mynumber);
editTextEmail = (EditText) findViewById(R.id.editTextEmail);
editTextFirstName = (EditText) findViewById(R.id.editTextFirstName);
editTextLastName = (EditText) findViewById(R.id.editTextLastName);
editTextPassword = (EditText) findViewById(R.id.editTextPassword);
editTextConfirmPassword = (EditText) findViewById(R.id.editTextConfirmPassword);
editTextNumber = (EditText) findViewById(R.id.editTextNumber);
mynumber = (TextView) findViewById(R.id.mynumber);
editTextAge = (EditText) findViewById(R.id.editTextAge);

btnCreateAccount = (Button) findViewById(R.id.buttonCreateAccount);
btnCreateAccount.setOnClickListener(new View.OnClickListener() {

我不知道出了什么问题,但我无法看到&#34;创建帐户&#34;按钮了。可能是由于XML的变化。

2 个答案:

答案 0 :(得分:0)

这是因为您要将EditText宽度设置为fill_parent,这会占用设备的宽度并停止按钮显示。

更改:将EditText的宽度和高度更改为wrap_content

请尝试以下数据:

<?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:background="#123456"
    android:gravity="center_vertical"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/editTextEmail"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="Email" />

    <requestFocus />

    <EditText
        android:id="@+id/editTextFirstName"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="First Name" />

    <EditText
        android:id="@+id/editTextLastName"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="Last Name" />

    <EditText
        android:id="@+id/editTextPassword"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="Password"
        android:inputType="textPassword" />

    <EditText
        android:id="@+id/editTextConfirmPassword"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="Confirm Password"
        android:inputType="textPassword" />

    <EditText
        android:id="@+id/editTextAge"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="Age" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_horizontal"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/mynumber"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Number +961"
            android:textSize="20sp"
            android:color="@android:color/white" />

        <EditText
            android:id="@+id/editTextNumber"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="Number" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/ic_launcher"
            android:gravity="center_vertical"
            android:orientation="vertical" >

            <Button
                android:id="@+id/buttonCreateAccount"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_marginBottom="60dp"
                android:background="@android:color/white"
                android:text="Create Account" />

        </LinearLayout>
    </LinearLayout>
</LinearLayout>

希望它有效

答案 1 :(得分:0)

尝试替换:

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/mynumber"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Number +961"
        android:textSize="20sp"
        android:color="@color/black" />

    <EditText
        android:id="@+id/editTextNumber"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="Number" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/ic_signup"
        android:gravity="center_vertical"
        android:orientation="vertical" >

        <Button
            android:id="@+id/buttonCreateAccount"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginBottom="60dp"
            android:background="@color/androidwhite"
            android:text="Create Account" />

    </LinearLayout>
</LinearLayout>

这样,如果你想让你的按钮在editTextNumber的右边:

    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center_horizontal" 
    android:orientation="horizontal">
    <TextView 
        android:id="@+id/mynumber" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Number +961" 
        android:textSize="20sp" 
        android:color="@color/black" /> 
    <EditText 
        android:id="@+id/EditTextNumber" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:hint="Number" /> 
    <Button 
            android:id="@+id/buttonCreateAccount" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:background="@color/white" 
            android:text="Create Account" /> 
</LinearLayout>

或者如果你想在editText下使用你的按钮:

    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center_horizontal" 
    android:orientation="horizontal">
    <TextView 
        android:id="@+id/mynumber" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Number +961" 
        android:textSize="20sp" 
        android:color="@color/black" /> 
    <EditText 
        android:id="@+id/EditTextNumber" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:hint="Number" /> 
</LinearLayout>
<Button 
    android:id="@+id/buttonCreateAccount" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:layout_gravity="center" 
    android:background="@color/white" 
    android:text="Create Account" />