键盘出现时屏幕缩小

时间:2018-02-12 13:54:30

标签: android xamarin.android screen soft-keyboard shrink

我在Android应用程序上有以下屏幕:

enter image description here

当我按下SearchView时,屏幕会缩小:

enter image description here

当键盘出现时,我希望屏幕保持静止(如第一张图片中所示)。 这是我的xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="10"
    android:minWidth="25px"
    android:minHeight="25px">
    <SearchView
        android:minWidth="25px"
        android:minHeight="25px"
        android:background="@drawable/rounded_border"
        android:clickable="true"
        android:iconifiedByDefault="false"
        android:focusable="false"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:id="@+id/searchViewCustomers" />
    <android.support.v7.widget.RecyclerView
        android:id="@+id/customersRecyclerView"
        android:scrollbars="vertical"
        android:layout_weight="8"
        android:layout_width="match_parent"
        android:layout_height="0dp" />
    <Button
        android:text="Нов"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:id="@+id/button1" />
</LinearLayout>

我已经尝试过在互联网上找到的解决方案,但它们对我不起作用,可能是因为它们适用于Android(Java)。如果有一种方法可以做,而不是在xml而不是在C#代码中,它会好得多。

1 个答案:

答案 0 :(得分:1)

  

当键盘出现时,我希望屏幕保持静止(如第一张图片中所示)。

如果您不希望自动调整屏幕,可以将活动的WindowSoftInputMode设置为SoftInput.AdjustNothing,如下所示:

[Activity(Label = "Sample", MainLauncher = true,WindowSoftInputMode = SoftInput.AdjustNothing)]
public class MainActivity : Activity
{
    RecyclerView mRecyclerView;
    private RecyclerView.Adapter mAdapter;
    private RecyclerView.LayoutManager mLayoutManager;
    ...
}