我在布局中具有以下代码。我在SearchView
]底部有RelativeLayout
我想在焦点集中时将searchview放在键盘顶部
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:showIn="@layout/activity_main"> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerview" android:foregroundGravity="top" android:layout_width="match_parent" android:layout_height="530dp" android:layout_alignParentTop="true" android:transcriptMode="alwaysScroll" /> <android.support.v7.widget.SearchView android:id="@+id/searchview" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/recyclerview" android:layout_alignParentBottom="true" android:iconifiedByDefault="false" /> </RelativeLayout>
我尝试了以下代码,但未按预期工作
Android是否默认执行此操作?
searchview.FocusChange += Searchview_FocusChange;
private void Searchview_FocusChange(object sender, View.FocusChangeEventArgs e)
{
if (e.HasFocus)
{
searchview.Parent.BringChildToFront(searchview);
searchview.BringToFront();
}
}
我该如何解决?我没有运气尝试过其他帖子中提到的一些选项。
作为一项变通办法,我添加了以下代码,但对此感到不舒服
searchview.Click += Searchview_Click;
private void Searchview_Click(object sender, System.EventArgs e) { if (sender is SearchView searchview) { searchview.Parent.BringChildToFront(searchview); searchview.BringToFront(); searchview.SetY(searchview.GetY() - 100); searchview.SetY(searchview.GetY() + 100); } }
我在布局中具有以下代码。我在RelativeLayout的底部有SearchView,我想在焦点获得时将searchview放在键盘顶部
您应将RelativeLayout