Android RelativeLayout在底部切断

时间:2015-11-15 15:13:18

标签: android android-layout

我有这样的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/screen01_bg"
    android:gravity="center_horizontal">

    <RelativeLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#7fb9e5"
        android:layout_gravity="center_horizontal"
        android:paddingTop="10dp"
        android:paddingBottom="10dip">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Login with an existing account"
            android:id="@+id/textView5"
            android:layout_gravity="center"
            android:textColor="#FFF"
            android:textStyle="bold"
            android:layout_centerInParent="true"/>
    </RelativeLayout >

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="20dp">
        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="2" >

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/facebook"
                android:src="@drawable/facebook"
                android:adjustViewBounds="true"
                android:cropToPadding="false"
                android:background="#00000000"
                android:scaleType="fitXY"/>
        </LinearLayout>
        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="20dp">
        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="2" >

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/twitter"
                android:src="@drawable/twitter"
                android:adjustViewBounds="true"
                android:cropToPadding="false"
                android:background="#00000000"
                android:scaleType="fitXY"/>
        </LinearLayout>
        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:nestedScrollingEnabled="false"
        android:gravity="fill_horizontal|top|center_vertical|fill"
        android:paddingTop="5dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="or"
            android:id="@+id/textView9"
            android:singleLine="true"
            android:textStyle="italic"
            android:layout_centerInParent="true"
            android:textColor="#FFF" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Login with an email and password"
            android:id="@+id/textView10"
            android:singleLine="true"
            android:layout_below="@+id/textView9"
            android:textStyle="bold"
            android:layout_centerInParent="true"
            android:textColor="#FFF" />
        <EditText
            android:id="@+id/email"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/textView10"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="26dp"
            android:inputType="textEmailAddress"
            android:hint="Email"
            android:gravity="center_horizontal"
            android:ems="10"
            android:background="@drawable/rect"
            android:padding="10px">
            <requestFocus />
        </EditText>
        <EditText
            android:id="@+id/password"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/email"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="26dp"
            android:ems="10"
            android:hint="Password"
            android:gravity="center_horizontal"
            android:background="@drawable/rect"
            android:inputType="textPassword"
            android:padding="10px">
        </EditText>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Login"
            android:id="@+id/login_button"
            android:layout_below="@+id/password"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="26dp"
            android:background="@drawable/login_button"
            >
        </Button>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="@string/create_new_account"
            android:id="@+id/create_account"
            android:layout_below="@+id/login_button"
            android:singleLine="true"
            android:textStyle="italic"
            android:layout_centerHorizontal="true"
            android:textColor="#FFF" />
    </RelativeLayout>

</LinearLayout>

它在Android Studio的预览中显示得很好,但是当我运行它时,内容在底部被截断。 这是屏幕截图: here

我不知道可能的原因是什么。 login_button布局位于:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#7fb9e5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <corners android:radius="0dp" />
    <stroke android:width="5px" android:color="#FFF" />
</shape>

只是一个带边框的简单按钮。 那么什么是更好的方法或如何解决这个问题?

3 个答案:

答案 0 :(得分:1)

使用此布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ee3"
    android:gravity="center_horizontal">

    <RelativeLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#7fb9e5"
        android:layout_gravity="center_horizontal"
        android:paddingTop="10dp"
        android:paddingBottom="10dip">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Login with an existing account"
            android:id="@+id/textView5"
            android:layout_gravity="center"
            android:textColor="#FFF"
            android:textStyle="bold"
            android:layout_centerInParent="true"/>
    </RelativeLayout >

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="20dp">
        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="2" >

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/facebook"
                android:src="@drawable/facebook"
                android:adjustViewBounds="true"
                android:cropToPadding="false"
                android:background="#00000000"
                android:scaleType="fitXY"/>
        </LinearLayout>
        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="20dp">
        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="2" >

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/twitter"
                android:src="@drawable/ic_fb_icon"
                android:adjustViewBounds="true"
                android:cropToPadding="false"
                android:background="#00000000"
                android:scaleType="fitXY"/>
        </LinearLayout>
        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
android:gravity="center_horizontal"
        android:paddingTop="5dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="or"
            android:id="@+id/textView9"
            android:singleLine="true"
            android:textStyle="italic"
            android:layout_centerInParent="true"
            android:textColor="#FFF" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Login with an email and password"
            android:id="@+id/textView10"
            android:singleLine="true"
            android:layout_below="@+id/textView9"
            android:textStyle="bold"
            android:layout_centerInParent="true"
            android:textColor="#FFF" />
        <EditText
            android:id="@+id/email"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/textView10"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="26dp"
            android:inputType="textEmailAddress"
            android:hint="Email"
            android:gravity="center_horizontal"
            android:ems="10"
            android:background="#333"
            android:padding="10px">
            <requestFocus />
        </EditText>
        <EditText
            android:id="@+id/password"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/email"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="26dp"
            android:ems="10"
            android:hint="Password"
            android:gravity="center_horizontal"
            android:background="#333"
            android:inputType="textPassword"
            android:padding="10px">
        </EditText>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Login"
            android:id="@+id/login_button"
            android:layout_below="@+id/password"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="26dp"
            android:background="@drawable/sobuttonbg"
            />


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="create_new_account"
            android:id="@+id/create_account"
            android:layout_below="@+id/login_button"
            android:singleLine="true"
            android:textStyle="italic"
            android:layout_centerHorizontal="true"
            android:textColor="#FFF" />
    </LinearLayout>
</LinearLayout>

**注意:请相应更改图标

答案 1 :(得分:1)

您需要指定minHeightminWidth属性并将其设置为0dp,并将padding属性设置为边框间距所需的值和按钮文字。

以下适用于我:

Button Background Drawable:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <shape android:shape="rectangle">
            <solid android:color="@color/pressedButtonBlue" />
            <corners android:radius="36dp"/>
        </shape>
    </item>
    <item android:state_enabled="false">
        <shape android:shape="rectangle">
            <solid android:color="@color/disabledButtonBlue" />
            <corners android:radius="36dp"/>
        </shape>
    </item>
    <item android:state_enabled="true">
        <shape android:shape="rectangle">
            <solid android:color="@color/defaultButtonBlue" />
            <corners android:radius="36dp"/>
        </shape>
    </item>
    <item android:state_focused="true">
        <shape android:shape="rectangle">
            <solid android:color="@color/pressedButtonBlue" />
            <corners android:radius="36dp"/>
        </shape>
    </item>
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/defaultButtonBlue" />
            <corners android:radius="36dp"/>
        </shape>
    </item>
</selector>

布局:

<RelativeLayout
    android:id="@+id/new_message_wrapper"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:padding="5dp">
    <Button
        android:id="@+id/cancel_new_message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:gravity="center"
        android:layout_centerVertical="true"
        android:minHeight="0dp"
        android:minWidth="0dp"
        android:paddingTop="5dp"
        android:paddingBottom="5dp"
        android:paddingRight="15dp"
        android:paddingLeft="15dp"
        android:background="@drawable/button_bg"
        android:text="Cancel"
        android:textAllCaps="false"
        android:textColor="@android:color/white"
        android:textSize="14sp" />
</RelativeLayout>

答案 2 :(得分:0)

  1. 你不能在形状xml中执行此操作

        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
    
  2. 这样做

    <solid android:color="#7fb9e5"/>
    
    1. layout_marginBottom26dp5dplogin_buttonemail减少到 <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Login" android:id="@+id/login_button" android:layout_below="@+id/password" android:layout_centerHorizontal="true" android:layout_marginBottom="5dp" android:background="@drawable/login_button"/>

      <a href= "profile?'some id fetch from php'"
相关问题