我有一个简单的布局如下:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#D23456" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#FFFFFF" >
<ImageView
android:layout_width="match_parent"
android:layout_height="800dp"
android:src="@drawable/ic_launcher" />
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
scrollview的背景是粉红色,线性布局里面有android图标图像,高度为800dp(不适合屏幕).我期待看到的是,imageview浮动在粉红色的背景中,每边(顶部,底部,左侧,右侧)的边距为10dp.但是当我滚动到底部时,滚动视图不会滚动到保证金,所以滚动的底部是imageview而不是粉红色的边距.
我怎么能阻止这个?这使用户认为页面尚未结束并使他想要滚动更多.
我有一个活动,其布局内容如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
style="@style/ToolBarStyle.Event" />
<com.mypackage.corecode.ui.view.SlidingTabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/primary_color" />
<android.support.v4.view.ViewPager
android:id="@+id/vendor_main_tabview_pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
在viewpager中,我有一个片段,它具有以下布局:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="3"
android:orientation="horizontal">
<EditText
android:theme="@style/ScrollableContentThemeNoActionBar"
android:id="@+id/edit_text_vendor_sms_phone_number"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:inputType="number" />
<Button
android:id="@+id/button_send_sms"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
当片段内的内容不适合屏幕时,滚动视图允许用户查看屏幕下方的内容.(按预期工作)
问题是当edittext获得焦点时,键盘与edittext区域重叠,而不是滚动视图导致内容滚动.
我希望片段能够处理键盘和scrollview以适应屏幕上的键盘.
或者我错了,是否对键盘负责?由于活动布局中的根视图是linearlayout,它是否限制了扩展?
我尝试用滚动视图包装活动布局的整个内容,但是如果我没有给它一个固定的大小,这次viewpager不会出现在屏幕上.即使我这样做,我最终在片段内部有一个滚动视图,它位于主布局的滚动视图下方,而键盘仍然在编辑文本上方盘旋.
我在这里有点迷失,我的目标是能够在编辑文本聚焦时滚动片段内容,而是键盘当前与edittext重叠.