2016-07-07 2 views
0

У меня есть карта Макет, содержащий ScrollView с редактированием внутри него, ниже которого есть две кнопки.Переместить кнопки на клавиатуре открыть Android

У меня возникла проблема, когда я открываю клавиатуру и печатаю до тех пор, пока не будет достаточно текста, чтобы Edit начал разворачивать кнопки, скрываясь под клавиатурой.

Я хотел бы сделать так, чтобы кнопки всегда находились над клавиатурой так же, как нижняя часть 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> 

спасибо за любую помощь! Это на самом деле у меня

ответ

0

Замените ваш LinearLayout с RelativeLayout, совместите ScrollView к началу нового RelativeLayout, установить идентификатор контейнера кнопок (другой RelativeLayout к buttonsLayout - как и следовало ожидать от 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> 
Смежные вопросы