[英]How to set buttons at the bottom of a scrollView such that the buttons are covered by the softkeyboard
[英]How to scroll to bottom scrollView when softkeyboard is open
當編輯文本請求焦點和軟鍵盤打開時,我需要scrollView滾動到底部。 這是我的xml代碼:
<ScrollView
android:id="@+id/transfer_scroller"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/blue_500"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="@+id/cv_transfer_senderLayout"
style="@style/CardViewStyle.Transaction">
<LinearLayout
android:id="@+id/ll_selectRec"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/cv_transfer_receiverLayout"
android:visibility="gone"
android:layout_below="@id/cv_transfer_senderLayout"
style="@style/CardViewStyle.Transaction">
<LinearLayout
android:id="@+id/transfer_layout_ll_receivers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/cv_transfer_setAmount"
android:visibility="gone"
android:layout_below="@id/cv_transfer_receiverLayout"
style="@style/CardViewStyle.Transaction">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<EditText
android:id="@+id/transfer_layout_et_money"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:digits="0123456789"
android:hint="@string/hint_ed_ll_money"
android:inputType="phone"
android:gravity="center"
android:maxLength="7"
android:singleLine="true"
android:textColor="@color/gray_400"
android:textSize="@dimen/font_summ" >
</EditText>
</LinearLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
</ScrollView>
這是我嘗試的方法,因此請滾動至底部:
private void scrollDown(){
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mScrollView.scrollTo(0, mScrollView.getBottom());
Log.v("55555", "scrollDown");
}
}, 50);
}
mEditAmount.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
scrollDown();
}
});
但這無濟於事。 鍵盤是打開的,可以覆蓋其余的布局...有什么主意嗎?
我不確定您的問題是什么,是滾動視圖無法到達底部,還是您不希望軟鍵盤覆蓋滾動視圖?
對於第一個問題,您可以在處理程序中嘗試以下操作:
mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
或者,您可以像這樣更改代碼:
if (scroll == null || inner == null) {
return;
}
int offset = inner.getMeasuredHeight() - scroll.getHeight();
if (offset < 0) {
offset = 0;
}
scroll.scrollTo(0, offset);
如果您不希望軟鍵盤覆蓋您的布局,則可以嘗試以下方法。
第一種方式:在OnCreate()中,在“ setContentView”之前編寫代碼:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
第二種方式:在AndroidManifest.xml的“活動”中編寫以下代碼:
android:windowSoftInputMode="adjustPan"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.