【发布时间】:2017-02-17 17:08:22
【问题描述】:
我在RecyclerView 中有几个EditText 在BottomSheetDialog 中。我现在遇到的问题是,当屏幕上显示BottomSheetDialog 时,我点击例如RecyclerView 中的第7 个EditText。软键盘出现并覆盖EditText,所以我看不到我输入的内容。但是如果我将BottomSheetDialog 向上拖动一点,EditText 将不会被软键盘覆盖,即使我点击屏幕上的最后一个EditText。 RecyclerView 在这种情况下肯定会调整大小,但如果我不向上拖动 BottonSheetDialog 则不会调整大小。知道为什么吗?以及如何解决这个问题?
Main.java
class VH extends RecyclerView.ViewHolder {
public VH(View itemView) {
super(itemView);
}
}
private void test() {
BSTest bsTest = new BSTest(this);
bsTest.setContentView(R.layout.bottomsheet_test);
RecyclerView rv = (RecyclerView) bsTest.findViewById(R.id.recyclerView);
rv.setLayoutManager(new LinearLayoutManager(this));
rv.setAdapter(new RecyclerView.Adapter() {
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new VH(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_edittext, parent, false));
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
}
@Override
public int getItemCount() {
return 20;
}
});
bsTest.show();
}
BSTest.java
public class BSTest extends BottomSheetDialog {
public BSTest(@NonNull Context context) {
super(context);
}
private BSTest(@NonNull Context context, @StyleRes int theme) {
super(context, theme);
}
private BSTest(@NonNull Context context, boolean cancelable, OnCancelListener cancelListener) {
super(context, cancelable, cancelListener);
}
}
bottomsheet_test.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="1"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="2"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="3"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
item_edittext.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="1"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="2"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="3"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
【问题讨论】:
-
显示截图
-
我添加了一个短视频
-
@user1865027 你找到问题/解决问题了吗?
-
@NitinMisra 试试这个stackoverflow.com/questions/39288879/…(目前正在测试)
-
@NitinMisra 试试这个全屏stackoverflow.com/questions/33361569/…
标签: android android-softkeyboard bottom-sheet