Android ScrollView高度未更改
我有一个包含以下XML的布局:Android ScrollView高度未更改,android,android-layout,height,scrollview,Android,Android Layout,Height,Scrollview,我有一个包含以下XML的布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="mat
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:id="@+id/myScrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true" >
<LinearLayout
android:id="@+id/myEditLinearLayout"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<EditText
android:id="@+id/myEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="8dip"
android:paddingRight="8dip"
android:maxLines="300"
android:scrollHorizontally="false"
android:hint="Type notes here..."
android:inputType="textNoSuggestions|textMultiLine"
android:layout_gravity="center_horizontal|center_vertical"
android:gravity="left"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="@+id/layoutKbd"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<android.inputmethodservice.KeyboardView
android:id="@+id/myKeyboardView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:keyPreviewLayout ="@layout/kbdpreview"
android:visibility="gone" />
</RelativeLayout>
</RelativeLayout>
上述方法不起作用。它在设置scrollView高度之前和之后显示scrollBounds.bottom的相同值
我遗漏了什么?将属性
android:layout_above="@+id/yourKeyboardLayout"
在滚动视图中。您可以尝试将
android:windowSoftInputMode=“adjustPan”
放入清单中。如果你不喜欢这个结果,也许你可以用别的平底锅
加上这个
android:WindowsOfInputMode=“adjustPan”
在声明活动的清单中,您还可以在滚动视图中添加
如果要更改scrollview的LayoutParams,应在示例中使用以下代码:
ViewGroup.LayoutParams lp = scrollView.getLayoutParams();
lp.height = editTextBottom + kbdHeight + 20;
scrollview.setLayoutParams(lp);
我相信,通过让自定义键盘xml包含layout_below属性,您可以在布局文件中完全解决这个问题。@radix,我认为这不是正确的方法。由于ScrollView不是固定的,因此键盘可能不是父底。@user2346980我同意,我的想法是证明这更多的是UI更改,而不是代码。OP可以根据他的需要和要求修改。我不确定我是否理解Radix的建议@Radix,你介意用示例代码来解释吗?这个建议的一个变体有效。最后,我将andoid:layout_设置为自定义键盘的属性,然后每当显示自定义键盘时,我都将scrollview高度设置为(keyboardBottom-keyboardHeight)。这很有魅力!不幸的是,这没有起作用。顺便说一句,这个建议和我已有的不一样吗?也就是说,这个建议和scrollView.getLayoutParams()有什么区别。height=editTextBottom+kbdHeight+20;这是行不通的。清单现在有行,ScrollView定义为…正如我在上面的评论中提到的,这不起作用。谢谢。这一建议的一个变体奏效了。最后,我将andoid:layout_设置为自定义键盘的属性,然后每当显示自定义键盘时,我都将scrollview高度设置为(keyboardBottom-keyboardHeight)。这很有魅力!
ViewGroup.LayoutParams lp = scrollView.getLayoutParams();
lp.height = editTextBottom + kbdHeight + 20;
scrollview.setLayoutParams(lp);