Android版的RelativeLayout与WRAP_CONTENT截断有的孩子 [英] Android RelativeLayout with wrap_content truncates some children

查看:153
本文介绍了Android版的RelativeLayout与WRAP_CONTENT截断有的孩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个RelativeLayout的,其宽度/高度设置为wrap_content。然而,在右下角的按钮被截断在其下侧。
改变的RelativeLayout的paddingBottom会没有帮助,同样没有加入marginBottom的按钮。

I have a RelativeLayout whose width/height is set to wrap_content. However, the button in the bottom right is truncated on its lower side. Changing the RelativeLayout's paddingBottom doesn't help, neither does adding a marginBottom to the button.

任何想法?

下面是我的code:

<RelativeLayout
    android:id="@+id/sign_up_phase_enteraddress"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:paddingTop="10dp"
    android:paddingRight="10dp"
    android:paddingBottom="10dp"
    android:paddingLeft="10dp"
    android:background="#ff6aa639"
     >

    <TextView
        android:id="@+id/sign_up_signuphere"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginBottom="29dp"
        android:text="@string/sign_up_signuphere"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/sign_up_emaillabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/sign_up_signuphere"
        android:layout_alignLeft="@id/sign_up_signuphere"
        android:layout_alignBaseline="@+id/sign_up_email"
        android:text="@string/sign_up_emailaddress"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/sign_up_email"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginLeft="46dp"
        android:layout_below="@id/sign_up_signuphere"
        android:layout_toRightOf="@id/sign_up_emaillabel"
        android:ems="10"
        android:inputType="textEmailAddress" >

        <requestFocus />

    </EditText>

    <Button
        android:id="@+id/sign_up_signup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/sign_up_haveaccount"
        android:layout_alignRight="@id/sign_up_email"
        android:layout_below="@id/sign_up_email"
        android:text="@string/sign_up_signup" />

    <TextView
        android:id="@+id/sign_up_haveaccount"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@id/sign_up_emaillabel"
        android:layout_marginTop="27dp"
        android:layout_below="@id/sign_up_email"
        android:text="@string/sign_up_haveaccount"
        android:textAppearance="?android:attr/textAppearanceSmall" />


</RelativeLayout>

......,这就是它看起来像在模拟器:

...and this is what it looks like in the emulator:

我如何能得到我的按钮的下方,显示有什么想法?
TIA!

Any thoughts on how I can get the bottom of my button to show? TIA!

推荐答案

我的快的想法是底边框设置按钮上的文字高度使用XML code左

My fast idea is to set button bottom border to height of text on the left by using xml code

android:layout_alignBottom="@+id/sign_up_haveaccount"

因为你已经设置好的 layout_below 选项了。但是你的XML code是非常不妥当的:)我会尽量写在这里更好的XML code你,更高版本。

because you've setted layout_below option already. However your xml code is quite not proper :) I will try write here better xml code for you, later.

好吧,我发现你的问题。我正在寻找解决方案。
我设置好的TextView的为新填充底部,因为按钮被对准这个TextView的basline。我知道这可能是一个不错的技巧,但我发现coudln't安迪来处理它好办法:)

Well, I found your problem. And I was searching for solution. I setted for textview new padding bottom because button was aligned to this textview basline. I know that it could be a nice hack but I coudln't find andy good way to handle it :)

根据您的布局我改变的EditText,使其伸缩行为。此外,我归纳所有元素分成3组。每行每使其更具可读性。

According to your layout I changed behaviour for edittext to make it stretchable. Also I grouped all elements into 3 groups. Each one per row to make it more readable.

另外不要忘记,前两行关于XM​​L的。

Also do not forget that first 2 lines about xmls.

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/sign_up_phase_enteraddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#ff6aa639"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp" >

<!-- 1 row -->

<RelativeLayout
    android:id="@+id/row1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="29dp" >

    <TextView
        android:id="@+id/sign_up_signuphere"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/sign_up_signuphere"
        android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>

<!-- 2 row -->

<RelativeLayout
    android:id="@+id/row2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/row1" >

    <TextView
        android:id="@+id/sign_up_emaillabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/sign_up_email"
        android:text="@string/sign_up_emailaddress"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/sign_up_email"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginLeft="20dp"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@+id/sign_up_emaillabel"
        android:inputType="textEmailAddress" >

        <requestFocus />
    </EditText>
</RelativeLayout>

<!-- 3 row -->

<RelativeLayout
    android:id="@+id/row3"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/row2" >

    <TextView
        android:id="@+id/sign_up_haveaccount"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="27dp"
        android:paddingBottom="15dp"
        android:text="@string/sign_up_haveaccount"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <Button
        android:id="@+id/sign_up_signup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/sign_up_haveaccount"
        android:layout_alignParentRight="true"
        android:text="@string/sign_up_signup" />
</RelativeLayout>

</RelativeLayout>

这篇关于Android版的RelativeLayout与WRAP_CONTENT截断有的孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆