簡體   English   中英

在打開鍵盤的Android上向上移動按鈕

[英]Move buttons up on keyboard open Android

我有一個卡片布局,其中包含一個ScrollView及其內部的Edit,在其下方是2個按鈕。

我遇到一個問題,當我打開鍵盤並鍵入直到有足夠的文本使編輯開始展開時,“按鈕”才隱藏在鍵盤下。

我要使按鈕始終位於鍵盤上方,就像EditText的底部始終位於鍵盤上方一樣。

我的布局如下:

CardView
   LinearLayout(Vertical)
       ScrollView
           EditText
       ButtonsLayout
           Button
           Button

<android.support.v7.widget.CardView
        android:id="@+id/cv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:clickable="true"
        android:foreground="?android:attr/selectableItemBackground"
        android:visibility="visible"
        app:cardElevation="4dp"
        app:cardUseCompatPadding="true">


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
          >

            <ScrollView
                android:id="@+id/scrollView2"
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_above="@+id/buttonsLayout"
                android:fadeScrollbars="false"
                android:layout_weight="1">


                            <EditText
                                android:id="@+id/et_1"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginLeft="10dp"
                                android:layout_marginRight="10dp"
                                android:clickable="true"
                                android:ems="10"
                                android:hint="What&apos;s on your mind?"
                                android:inputType="textCapSentences|textMultiLine"
                                android:maxLength="300" />



            </ScrollView>


            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <android.support.design.widget.FloatingActionButton
                    android:id="@+id/fabAttach"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentTop="true"
                    android:layout_marginBottom="10dp"
                    android:layout_marginLeft="125dp"
                    android:layout_marginStart="125dp"
                    android:clickable="true"
                    android:onClick="onAttachClicked"
                    android:src="@drawable/ic_attach"
                    android:visibility="visible"

                    app:borderWidth="0dp" />


                <android.support.design.widget.FloatingActionButton
                    android:id="@+id/fabPost"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:layout_marginBottom="10dp"
                    android:layout_marginLeft="10dp"
                    android:layout_toEndOf="@+id/fabAttach"
                    android:layout_toRightOf="@+id/fabAttach"
                    android:clickable="true"
                    android:onClick="onPostSquawkClicked"
                    android:src="@drawable/ic_send_white"

                    app:borderWidth="0dp" />


            </RelativeLayout>

        </LinearLayout>


    </android.support.v7.widget.CardView>

非常感謝您的幫助! 真的有我

將您的LinearLayout替換為RelativeLayout ,將ScrollView對准新的RelativeLayout的頂部,將按鈕容器的ID設置(另一個RelativeLayoutbuttonsLayout ,這是ScrollView所期望的;在同一按鈕容器上,將其對准以下位置)父級RelativeLayout並將其高度設置為wrap_content ):

<android.support.v7.widget.CardView
    android:id="@+id/cv"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:foreground="?android:attr/selectableItemBackground"
    android:visibility="visible"
    app:cardElevation="4dp"
    app:cardUseCompatPadding="true">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ScrollView
            android:id="@+id/scrollView2"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_alignParentTop="true"
            android:layout_above="@+id/buttonsLayout"
            android:fadeScrollbars="false"
            android:layout_weight="1">

            <EditText
                android:id="@+id/et_1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:clickable="true"
                android:ems="10"
                android:hint="What&apos;s on your mind?"
                android:inputType="textCapSentences|textMultiLine"
                android:maxLength="300" />
        </ScrollView>

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

            <android.support.design.widget.FloatingActionButton
                android:id="@+id/fabAttach"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true"
                android:layout_marginBottom="10dp"
                android:layout_marginLeft="125dp"
                android:layout_marginStart="125dp"
                android:clickable="true"
                android:onClick="onAttachClicked"
                android:src="@drawable/ic_attach"
                android:visibility="visible"
                app:borderWidth="0dp" />

            <android.support.design.widget.FloatingActionButton
                android:id="@+id/fabPost"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_marginBottom="10dp"
                android:layout_marginLeft="10dp"
                android:layout_toEndOf="@+id/fabAttach"
                android:layout_toRightOf="@+id/fabAttach"
                android:clickable="true"
                android:onClick="onPostSquawkClicked"
                android:src="@drawable/ic_send_white"
                app:borderWidth="0dp" />
        </RelativeLayout>
    </RelativeLayout>
</android.support.v7.widget.CardView>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM