2017-04-17 128 views
0

当windowSoftInputMode =“adjustPan”时,当键盘覆盖按钮时是否可以滚动到与布局底部对齐的按钮?用打开的键盘滚动到底部并调整滑块

我不想使用windowSoftInputMode =“adjustResize”,因为我想让按钮位于键盘下方,而且我想在键盘打开时滚动到按钮。

布局例:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<ScrollView 
    android:id="@+id/scrollView" 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentTop="true"> 

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

     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="70dp" 
      android:hint="edit text" /> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="70dp" 
      android:hint="edit text" /> 

    </LinearLayout> 

</ScrollView> 

<Button 
    android:layout_width="match_parent" 
    android:layout_height="40dp" 
    android:layout_alignParentBottom="true" 
    android:text="button" /> 

</RelativeLayout> 

我需要滚动按钮是键盘下方:

img

回答

0

尝试此附加android.support.v4.widget.NestedScrollView代替的RelativeLayout,使android:transcriptMode="alwaysScroll"总是滚动

<android.support.v4.widget.NestedScrollView  
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
<ScrollView 
    android:id="@+id/scrollView" 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentTop="true" 
    android:transcriptMode="alwaysScroll"> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 
    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="70dp" 
     android:hint="edit text" /> 
    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="70dp" 
     android:hint="edit text" /> 
    <Button 
      android:layout_width="match_parent" 
      android:layout_height="40dp" 
      android:layout_alignParentBottom="true" 
      android:text="button" /> 
     </LinearLayout> 
    </ScrollView> 
</android.support.v4.widget.NestedScrollView>