【发布时间】:2016-02-08 08:02:08
【问题描述】:
我有一种情况,我需要一个滚动视图来拥有一个在移动时不应该与它的父级一起滚动的背景图像。在你们任何人建议我设置背景图像的链接之前,我已经尝试过但它不起作用。
整个故事是这样的:我有一个带有片段的活动,这些片段有自己的背景和一些输入字段。聚焦输入字段时,会出现键盘并挤压背景图像。为此,我在滚动视图的背景上放置了一张图片,解决了我挤压背景的问题,但引发了另一个担忧,即背景图片在滚动父滚动视图时应该保持静态。
你们中的任何人可能建议的第二个解决方案是设置我的活动背景,而不是使用滚动视图。没错,但为此我必须制作一个带有主题背景的样式元素,它在转换不同的片段时显得很奇怪,而且当我有很多代码和片段要向前和向后移动时它会增加开销。
这就是我卡住的地方。我已经浏览了下面的链接,如果您只想知道我是否尝试过。
下面是我用于片段的布局(全部以编程方式完成)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/top_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="none" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/backgroundView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/app_name"
android:scaleType="fitXY" />
<LinearLayout
android:id="@+id/parent_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</FrameLayout>
</ScrollView>
</LinearLayout>
因此,如果你们有任何更好的解决方案,请记住我的情况,将受到热烈欢迎。谢谢你
【问题讨论】:
-
在线性布局上设置背景。
-
当键盘出现时它会挤压背景视图!这是主要问题
标签: android scrollview android-softkeyboard