简体   繁体   English

Android:layout_below和layout_alignParentBottom

[英]Android: layout_below and layout_alignParentBottom

So I have the following layout 所以我有以下布局

ScrollView

RelativeLayout
    TextView1
    EditText1

    TextView2
    EditText2

    TextView3
    EditText3

    TextView4
    EditText4

    TextView5
    EditText5: 
         android:id="@+id/txtPassword"

    LinearLayout: 
         android:id="@+id/Linearlayout1"
         layout_alignParentBottom="true" 

         Button1
         Button2

Here's the problem When I click the txtPassword EditText to enter some text Button1&Button2 from the LinearLayout overlaps or becomes on top of txtPassword 这是问题所在,当我单击txtPassword EditText来输入一些文本时,LinearLayout中的Button1&Button2 重叠或变成txtPassword的顶部

Someone suggested that I use android:layout_below="@id/txtPassword" for the Linear Layout but that makes the layout_alignParentBottom="true" useless because it will put the LinearLayout right below txtPassword and not at the bottom. 有人建议我将android:layout_below =“ @ id / txtPassword”用于线性布局,但这会使layout_alignParentBottom =“ true”无效,因为它将把LinearLayout放在txtPassword下方而不是底部。

EDIT: Here's the Full Layout 编辑:这是完整布局

    <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/signatureScroller"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true" >

    <RelativeLayout 
        android:id="@+id/signatureLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#FFF"
        android:orientation="vertical"
        android:paddingBottom="20dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp" >

        <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_marginTop="20dp"
            android:text="@string/Meaning"
            android:textColor="#000"
            android:textSize="14sp" />

        <EditText
            android:id="@+id/txtMeaning"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/textView1"
            android:layout_below="@+id/textView1"
            android:layout_marginLeft="6dp"
            android:layout_marginRight="6dp"
            android:layout_marginTop="16dp"
            android:ems="10"
            android:enabled="false"
            android:inputType="text|textMultiLine"
            android:singleLine="true"
            android:textColor="#505050"
            android:textSize="14sp" >
        </EditText>

        <TextView
            android:id="@+id/TextView01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/textView1"
            android:layout_below="@+id/txtMeaning"
            android:layout_marginTop="16dp"
            android:text="@string/Comments"
            android:textColor="#000"
            android:textSize="14sp" />

        <EditText
            android:id="@+id/txtSignatureComments"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/TextView01"
            android:layout_below="@+id/TextView01"
            android:layout_marginLeft="6dp"
            android:layout_marginRight="6dp"
            android:layout_marginTop="16dp"
            android:ems="10"
            android:hint="@string/Comments"
            android:inputType="textMultiLine"
            android:maxLength="250"
            android:singleLine="false"
            android:textSize="14sp" />

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/textView1"
            android:layout_below="@+id/textView1"
            android:layout_marginTop="4dp"
            android:contentDescription="@string/Image"
            android:scaleType="fitXY"
            android:src="@drawable/line2" />

        <ImageView
            android:id="@+id/ImageView01"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/TextView01"
            android:layout_below="@+id/TextView01"
            android:layout_marginTop="4dp"
            android:contentDescription="@string/Image"
            android:scaleType="fitXY"
            android:src="@drawable/line2" />

        <TextView
            android:id="@+id/txtDuration"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/txtSignatureComments"
            android:layout_marginTop="16dp"
            android:text="@string/Duration2"
            android:textColor="#000"
            android:textSize="14sp" />

        <ImageView
            android:id="@+id/imgDuration"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/txtDuration"
            android:layout_marginTop="4dp"
            android:contentDescription="@string/Image"
            android:scaleType="fitXY"
            android:src="@drawable/line2" />

        <EditText
            android:id="@+id/txtHours"
            android:layout_width="140dp"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/imgDuration"
            android:layout_marginLeft="6dp"
            android:layout_marginTop="16dp"
            android:ems="10"
            android:hint="@string/Hours"
            android:inputType="number|textMultiLine"
            android:singleLine="true"
            android:textColor="#505050"
            android:textSize="14sp" >
        </EditText>

        <EditText
            android:id="@+id/txtMinutes"
            android:layout_width="140dp"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/txtHours"
            android:layout_alignParentRight="true"
            android:layout_marginRight="6dp"
            android:ems="10"
            android:hint="@string/Minutes"
            android:inputType="numberDecimal|text|textMultiLine"
            android:singleLine="true"
            android:textColor="#505050"
            android:textSize="14sp" >
        </EditText>

        <TextView
            android:id="@+id/txtException"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/txtHours"
            android:layout_marginTop="16dp"
            android:text="@string/Exception"
            android:textColor="#000"
            android:textSize="14sp" />

        <ImageView
            android:id="@+id/imgException"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/txtException"
            android:layout_marginTop="4dp"
            android:contentDescription="@string/Image"
            android:scaleType="fitXY"
            android:src="@drawable/line2" />

        <Spinner
            android:id="@+id/spnrException"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/imgException"
            android:layout_marginLeft="6dp"
            android:layout_marginRight="6dp"
            android:layout_marginTop="16dp" />

        <EditText
            android:id="@+id/txtExceptionDesc"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/spnrException"
            android:layout_marginLeft="6dp"
            android:layout_marginRight="6dp"
            android:layout_marginTop="8dp"
            android:ems="10"
            android:inputType="textMultiLine"
            android:maxLength="250"
            android:singleLine="false"
            android:textSize="14sp" >
        </EditText>

        <TextView
            android:id="@+id/txtPerformance"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/txtExceptionDesc"
            android:layout_marginTop="16dp"
            android:text="@string/PerformanceBased"
            android:textColor="#000"
            android:textSize="14sp" />

        <ImageView
            android:id="@+id/imgPerformance"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/txtPerformance"
            android:layout_marginTop="4dp"
            android:contentDescription="@string/Image"
            android:scaleType="fitXY"
            android:src="@drawable/line2" />

        <Spinner
            android:id="@+id/spnrPerformance"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/imgPerformance"
            android:layout_marginLeft="6dp"
            android:layout_marginRight="6dp"
            android:layout_marginTop="16dp" />

        <EditText
            android:id="@+id/txtUsername"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/spnrPerformance"
            android:layout_marginLeft="6dp"
            android:layout_marginRight="6dp"
            android:layout_marginTop="60dp"
            android:ems="10"
            android:hint="@string/Username"
            android:inputType="textCapCharacters|textAutoComplete"
            android:singleLine="true"
            android:textAllCaps="true"
            android:textSize="12sp" >

        </EditText>

        <EditText
            android:id="@+id/txtPassword"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/txtUsername"
            android:layout_marginLeft="6dp"
            android:layout_marginRight="6dp"
            android:layout_marginTop="10dp"
            android:ems="10"
            android:hint="@string/Password"
            android:inputType="textPassword"
            android:singleLine="true"
            android:textSize="12sp" />

        <LinearLayout
            android:id="@+id/LinearLayout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true" >

            <Button
                android:id="@+id/btnSave"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@drawable/button_detail_bg"
                android:text="@string/Sign"
                android:textColor="@drawable/button_detail_txt"
                android:textSize="16sp"
                android:textStyle="bold" />

            <Button
                android:id="@+id/btnCancel"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@drawable/button_detail_bg"
                android:text="@string/Cancel"
                android:textColor="@drawable/button_detail_txt"
                android:textSize="16sp"
                android:textStyle="bold" />
        </LinearLayout>
    </RelativeLayout>

</ScrollView>

You might want to see if this can be fixed using different windowSoftInputMode settings. 您可能想看看是否可以使用其他windowSoftInputMode设置解决此问题。 You could try to set android:windowSoftInputMode="adjustPan" for this specific activity. 您可以尝试为此特定活动设置android:windowSoftInputMode =“ adjustPan”。 It will than move up the UI if the keyboard is visible and focused on a edittext. 如果键盘可见并且将焦点放在编辑文本上,它将向上移动UI。 adjustResize can have the effect that some views overlap when the keyboard is visible. AdjustResize的效果是,当键盘可见时,某些视图会重叠。

use android:layout_below="@id/txtPassword" for the LinearLayout will work and doesn't make alignparentbottom="true" useless. 请使用android:layout_below =“ @ id / txtPassword” for LinearLayout可以正常工作,并且不会使alignparentbottom =“ true”失效。

try it 试试吧

<LinearLayout
        android:id="@+id/LinearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        layout_below="@id/txtPassword"
        android:layout_alignParentBottom="true" >

When you use a Relative Layout and the Keyboard will be opened you LinearLayout will be above the keyboard 当您使用相对布局并且键盘将被打开时,LinearLayout将位于键盘上方

I'll suggest another solution and I think it will work: 我将建议另一个解决方案,我认为它会起作用:

Use a LinearLayout as parent and the last LinearLayout height fill parent and set the gravity bottom try this: 使用LinearLayout作为父级,最后一个LinearLayout高度填充父级并设置重力底部,请尝试以下操作:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/signatureScroller"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >

<LinearLayout
    android:id="@+id/signatureLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#FFF"
    android:orientation="vertical"
    android:paddingBottom="20dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:text="@string/Meaning"
        android:textColor="#000"
        android:textSize="14sp" />

    <EditText
        android:id="@+id/txtMeaning"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_marginLeft="6dp"
        android:layout_marginRight="6dp"
        android:layout_marginTop="16dp"
        android:ems="10"
        android:enabled="false"
        android:inputType="text|textMultiLine"
        android:singleLine="true"
        android:textColor="#505050"
        android:textSize="14sp" >
    </EditText>

    <TextView
        android:id="@+id/TextView01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_marginTop="16dp"
        android:text="@string/Comments"
        android:textColor="#000"
        android:textSize="14sp" />

    <EditText
        android:id="@+id/txtSignatureComments"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_marginLeft="6dp"
        android:layout_marginRight="6dp"
        android:layout_marginTop="16dp"
        android:ems="10"
        android:hint="@string/Comments"
        android:inputType="textMultiLine"
        android:maxLength="250"
        android:singleLine="false"
        android:textSize="14sp" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_marginTop="4dp"
        android:contentDescription="@string/Image"
        android:scaleType="fitXY"
        android:src="@drawable/line2" />

    <ImageView
        android:id="@+id/ImageView01"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_marginTop="4dp"
        android:contentDescription="@string/Image"
        android:scaleType="fitXY"
        android:src="@drawable/line2" />

    <TextView
        android:id="@+id/txtDuration"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_marginTop="16dp"
        android:text="@string/Duration2"
        android:textColor="#000"
        android:textSize="14sp" />

    <ImageView
        android:id="@+id/imgDuration"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_marginTop="4dp"
        android:contentDescription="@string/Image"
        android:scaleType="fitXY"
        android:src="@drawable/line2" />

    <EditText
        android:id="@+id/txtHours"
        android:layout_width="140dp"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_marginLeft="6dp"
        android:layout_marginTop="16dp"
        android:ems="10"
        android:hint="@string/Hours"
        android:inputType="number|textMultiLine"
        android:singleLine="true"
        android:textColor="#505050"
        android:textSize="14sp" >
    </EditText>

    <EditText
        android:id="@+id/txtMinutes"
        android:layout_width="140dp"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/txtHours"
        android:layout_gravity="right"
        android:layout_marginRight="6dp"
        android:ems="10"
        android:hint="@string/Minutes"
        android:inputType="numberDecimal|text|textMultiLine"
        android:singleLine="true"
        android:textColor="#505050"
        android:textSize="14sp" >
    </EditText>

    <TextView
        android:id="@+id/txtException"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_marginTop="16dp"
        android:text="@string/Exception"
        android:textColor="#000"
        android:textSize="14sp" />

    <ImageView
        android:id="@+id/imgException"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_marginTop="4dp"
        android:contentDescription="@string/Image"
        android:scaleType="fitXY"
        android:src="@drawable/line2" />

    <Spinner
        android:id="@+id/spnrException"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_marginLeft="6dp"
        android:layout_marginRight="6dp"
        android:layout_marginTop="16dp" />

    <EditText
        android:id="@+id/txtExceptionDesc"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_marginLeft="6dp"
        android:layout_marginRight="6dp"
        android:layout_marginTop="8dp"
        android:ems="10"
        android:inputType="textMultiLine"
        android:maxLength="250"
        android:singleLine="false"
        android:textSize="14sp" >
    </EditText>

    <TextView
        android:id="@+id/txtPerformance"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_marginTop="16dp"
        android:text="@string/PerformanceBased"
        android:textColor="#000"
        android:textSize="14sp" />

    <ImageView
        android:id="@+id/imgPerformance"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_marginTop="4dp"
        android:contentDescription="@string/Image"
        android:scaleType="fitXY"
        android:src="@drawable/line2" />

    <Spinner
        android:id="@+id/spnrPerformance"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_marginLeft="6dp"
        android:layout_marginRight="6dp"
        android:layout_marginTop="16dp" />

    <EditText
        android:id="@+id/txtUsername"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_marginLeft="6dp"
        android:layout_marginRight="6dp"
        android:layout_marginTop="60dp"
        android:ems="10"
        android:hint="@string/Username"
        android:inputType="textCapCharacters|textAutoComplete"
        android:singleLine="true"
        android:textAllCaps="true"
        android:textSize="12sp" >

    </EditText>

    <EditText
        android:id="@+id/txtPassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/txtUsername"
        android:layout_marginLeft="6dp"
        android:layout_marginRight="6dp"
        android:layout_marginTop="10dp"
        android:ems="10"
        android:hint="@string/Password"
        android:inputType="textPassword"
        android:singleLine="true"
        android:textSize="12sp" />

    <LinearLayout
        android:id="@+id/LinearLayout1"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/btnSave"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/button_detail_bg"
            android:text="@string/Sign"
            android:textColor="@drawable/button_detail_txt"
            android:textSize="16sp"
            android:textStyle="bold"
            android:layout_gravity="bottom"
            android:gravity="bottom" />

        <Button
            android:id="@+id/btnCancel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/button_detail_bg"
            android:text="@string/Cancel"
            android:textColor="@drawable/button_detail_txt"
            android:textSize="16sp"
            android:textStyle="bold"
            android:layout_gravity="bottom"
            android:gravity="bottom" />
    </LinearLayout>
</LinearLayout>

</ScrollView>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM