按钮没有加宽

时间:2014-02-16 23:52:28

标签: android xml

我不能在我的Android项目上加宽按钮。我只对其中一个有问题。

这就是我得到的

enter image description here

这就是我想要的

enter image description here

只有按钮。这是我的相应问题的XML。

<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"
android:background="#4ECDC4"
tools:context=".MainActivity" >

<RelativeLayout
    android:id="@+id/rlSignInForm"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/rlSignInTitle"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:layout_marginTop="36dp" >

    <LinearLayout
        android:id="@+id/llSignInBody"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:background="#FFFFFF"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:orientation="vertical"
        android:visibility="visible"
        android:weightSum="2" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:layout_weight="1" >

            <ImageView
                android:id="@+id/ivEmailIcon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/email_icon"
                android:contentDescription="@null"
                android:layout_alignBottom="@+id/etSignInEmail"
                android:layout_marginBottom="2dp"/>

            <EditText
                android:id="@+id/etSignInEmail"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:background="@null"
                android:layout_toRightOf="@+id/ivEmailIcon"
                android:layout_marginLeft="10dp"
                android:gravity="bottom"
                android:hint="@string/email"
                android:inputType="textEmailAddress"
                android:textColor="@android:color/black"
                android:textSize="18sp" />
        </RelativeLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@drawable/sign_in_divider" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:layout_weight="1" >

            <ImageView
                android:id="@+id/ivPasswordIcon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/password_icon"
                android:contentDescription="@null"
                android:layout_alignBottom="@+id/etSignInPassword"
                android:layout_marginBottom="3dp"/>

            <EditText
                android:id="@+id/etSignInPassword"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:background="@null"
                android:layout_toRightOf="@+id/ivPasswordIcon"
                android:layout_marginLeft="10dp"
                android:gravity="bottom"
                android:hint="@string/password"
                android:inputType="textPassword"
                android:textColor="@android:color/black"
                android:textSize="18sp" />
        </RelativeLayout>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/llSignUpBody"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:background="#FFFFFF"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:orientation="vertical"
        android:visibility="visible"
        android:weightSum="3" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:layout_weight="1" >

            <ImageView
                android:id="@+id/ivUserNameIcon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/username_icon"
                android:contentDescription="@null"
                android:layout_alignBottom="@+id/etSignUpName"/>

            <EditText
                android:id="@+id/etSignUpName"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="10dp"
                android:layout_toRightOf="@+id/ivUserNameIcon"
                android:background="@null"
                android:gravity="bottom"
                android:hint="@string/username"
                android:singleLine="true"
                android:textColor="@android:color/black"
                android:textSize="18sp" />

        </RelativeLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@drawable/sign_in_divider" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:layout_weight="1" >

            <ImageView
                android:id="@+id/ivEmailIcon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/email_icon"
                android:contentDescription="@null"
                android:layout_alignBottom="@+id/etSignUpEmail"
                android:layout_marginBottom="2dp"/>

            <EditText
                android:id="@+id/etSignUpEmail"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="10dp"
                android:layout_toRightOf="@+id/ivEmailIcon"
                android:background="@null"
                android:gravity="bottom"
                android:hint="@string/email"
                android:inputType="textEmailAddress"
                android:textColor="@android:color/black"
                android:textSize="18sp" />

        </RelativeLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@drawable/sign_in_divider" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:layout_weight="1" >

            <ImageView
                android:id="@+id/ivPasswordIcon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/password_icon"
                android:contentDescription="@null"
                android:layout_alignBottom="@+id/etSignUpPassword"
                android:layout_marginBottom="3dp"/>

            <EditText
                android:id="@+id/etSignUpPassword"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="10dp"
                android:layout_toRightOf="@+id/ivPasswordIcon"
                android:background="@null"
                android:gravity="bottom"
                android:hint="@string/password"
                android:inputType="textPassword"
                android:textColor="@android:color/black"
                android:textSize="18sp" />

        </RelativeLayout>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/llForgotPasswordBody"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:background="#FFFFFF"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:orientation="vertical"
        android:weightSum="2"
        android:visibility="gone" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_margin="20dp"
            android:layout_weight="1" >

            <ImageView
                android:id="@+id/ivEmailIcon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/email_icon"
                android:contentDescription="@null"
                android:layout_alignBottom="@+id/etForgotPasswordEmail"
                android:layout_marginBottom="2dp"/>

            <EditText
                android:id="@+id/etForgotPasswordEmail"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:background="@null"
                android:layout_toRightOf="@+id/ivEmailIcon"
                android:layout_marginLeft="10dp"
                android:gravity="bottom"
                android:hint="@string/email"
                android:inputType="textEmailAddress"
                android:textColor="@android:color/black"
                android:textSize="18sp" />
        </RelativeLayout>
    </LinearLayout>
</RelativeLayout>

<Button
    android:id="@+id/btnForgotPassword"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/rlSignInForm"
    android:layout_below="@+id/rlSignInForm"
    android:layout_marginRight="5dp"
    android:layout_marginTop="5dp"
    android:background="@null"
    android:text="@string/forgot_password"
    android:textColor="#FFFFFF"
    android:textSize="14sp" />

<Button
    android:id="@+id/btnSendPassword"
    android:layout_width="175dp"
    android:layout_height="55dp"
    android:layout_below="@+id/rlSignInTitle"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="180dp"
    android:background="@drawable/rounded_rect_positive_selector"
    android:gravity="center"
    android:text="@string/SEND_PASSWORD"
    android:textColor="@android:color/white"
    android:textStyle="bold"
    android:width="175dp"
    android:height="55dp"
    android:visibility="gone" />

<Button
    android:id="@+id/btnActive"
    android:layout_width="175dp"
    android:layout_height="55dp"
    android:layout_alignLeft="@+id/btnInactive"
    android:layout_alignRight="@+id/rlSignInForm"
    android:layout_below="@+id/rlSignInTitle"
    android:layout_marginTop="280dp"
    android:background="#AD5BDB"
    android:gravity="center"
    android:text="@string/SIGN_IN"
    android:textColor="@android:color/white"
    android:textSize="22sp"
    android:textStyle="bold"
    android:visibility="visible" />

<Button
    android:id="@+id/btnInactive"
    style="@style/AppTheme"
    android:layout_width="175dp"
    android:layout_height="55dp"
    android:layout_alignLeft="@+id/rlSignInForm"
    android:layout_alignRight="@+id/rlSignInForm"
    android:layout_below="@+id/btnActive"
    android:layout_marginTop="14dp"
    android:background="#AD58DB"
    android:gravity="center"
    android:text="@string/SIGN_UP"
    android:textColor="@android:color/white"
    android:textSize="22sp"
    android:textStyle="bold"
    android:visibility="visible" />

<RelativeLayout
    android:id="@+id/rlNoInternetNotification"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/rlSignInTitle"
    android:visibility="gone" >

    <include layout="@layout/no_internet_notification" />
</RelativeLayout>

<RelativeLayout
    android:id="@+id/rlPushNotification"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/rlSignInTitle"
    android:visibility="gone" >

    <include layout="@layout/push_notification" />
</RelativeLayout>

<RelativeLayout
    android:id="@+id/rlSignInTitle"
    android:layout_width="match_parent"
    android:layout_height="44dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="30dp"
    android:background="#4ECDC4" >

    <com.cloverstudio.spika.view.MyriadProTextView
        android:id="@+id/tvSignInTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/SIGN_IN"
        android:textColor="@android:color/white"
        android:textSize="26sp" />
</RelativeLayout>

</RelativeLayout> 

较小的按钮为btnSendPassword,另一个按钮为btnActive。我试过玩宽度但没有改变。我是相当新的,所以任何解释为什么会发生这种情况会很好,所以我知道如果它再次发生了什么是错的。任何帮助都会很精彩。

2 个答案:

答案 0 :(得分:1)

您应该将btnSendPassword按钮与左侧和右侧的rlSignInForm对齐...然后您将达到您的要求。将btnSendPassword的以下XML代码段替换为btnSendPassword的现有XML代码段...您将解决所有问题。

<Button
    android:id="@+id/btnSendPassword"
    android:layout_width="175dp"
    android:layout_height="55dp"
    android:layout_below="@+id/rlSignInTitle"
    android:layout_alignLeft="@+id/rlSignInForm"
    android:layout_alignRight="@+id/rlSignInForm"
    android:layout_marginTop="180dp"
    android:background="@drawable/rounded_rect_positive_selector"
    android:gravity="center"
    android:text="@string/SEND_PASSWORD"
    android:textColor="@android:color/white"
    android:textStyle="bold"
    android:visibility="gone" />

答案 1 :(得分:0)

设置android:layout_width =“match_parent”。这应该可以解决你的问题。