代码之家  ›  专栏  ›  技术社区  ›  Profile3ForStack

键盘出现时屏幕缩小

  •  0
  • Profile3ForStack  · 技术社区  · 7 年前

    我在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 回复  |  直到 7 年前
        1
  •  1
  •   Elvis Xia - MSFT    7 年前

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

    如果不希望屏幕自动调整,可以设置 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;
        ...
    }