我有以下布局,可能有很多错误:
<FrameLayout
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"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#cccccc"
android:layout_marginBottom = "0dp">
<ScrollView android:id="@+id/ScrollView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<GridLayout
android:id="@+id/grid"
android:layout_margin="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_above="@+id/new_cancel"
android:alignmentMode="alignBounds"
android:columnCount="10"
android:columnOrderPreserved="false"
android:useDefaultMargins="true">
<TextView
// TextViews and EditText etc...
// ...
</GridLayout>
</ScrollView>
<Button
android:id="@+id/new_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="@color/colorPrimaryDark"
android:text="Cancel"
android:layout_margin="5dp"
/>
<Button
android:id="@+id/new_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:background="@color/colorPrimaryLight"
android:text="Ok"
android:layout_margin="5dp"
/>
</RelativeLayout>
</FrameLayout>
主要部分(GridLayout
)包含几个输入字段,用于输入文本,数字等。但是当我点击这样的输入字段时,触摸键盘会打开并覆盖部分输入字段!虽然此ViewGroup
位于ScrollView
内,但我无法滚动它!
如何更改布局以便我可以滚动GridLayout
...?
答案 0 :(得分:0)
在AndroidManifest
写
<activity
android:name="<yourpackage>.MainActivity"
...
android:windowSoftInputMode="adjustResize" />
这将在键盘打开时调整您的活动
答案 1 :(得分:0)
移除scrollView
并将其添加到您活动的onCreate
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
这会调整键盘打开时activity
的大小