以ScrollView为根的部局,不能从顶部显示其包含的页面内容

以ScrollView为根的部局,不能从顶部显示其包含的页面内容;是我最头疼的问题了,很多冲突一个一个的解决。到最后遇到这么一个问题,在网上搜搜,却不知道使用什么关键字查!网上资源就查到那几条关于这方面的论坛谈话。这也算是一个给遇到该麻烦的小伙伴们出了道难题,现在我就来解释一下!

问题由来:

基本上就是这样一个布局:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/shortMovieScrollView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#fff" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#f8f8f8" >

         <include
        android:id="@+id/lay_shortMovie_titleBar"
        layout="@layout/title_public_item1" />

        <TextView
            android:id="@+id/tvLine_1"
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:layout_alignBottom="@+id/lay_shortMovie_titleBar"
            android:background="#C8C7CC" />

        <RelativeLayout
            android:id="@+id/layout_filterBar"
            android:layout_width="fill_parent"
            android:layout_height="45dp"
            android:layout_below="@+id/lay_shortMovie_titleBar"
            android:background="#f8f8f8" >

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="45dp" >

                <TextView
                    android:id="@+id/tv_shortMovie_Selectleft"
                    android:layout_width="fill_parent"
                    android:layout_height="45dip"
                    android:layout_weight="1"
                    android:background="@drawable/btn_bg_color_selector"
                    android:drawableLeft="@drawable/icon_filter_teaching"
                    android:gravity="center_vertical"
                    android:paddingLeft="30dp"
                    android:text="筛选微电影"
                    android:textColor="#8f8f95"
                    android:textSize="16sp" />

                <ImageView
                    android:id="@+id/img_line_portrait"
                    android:layout_width="0.5dp"
                    android:layout_height="fill_parent"
                    android:background="#C8C7CC" />

                <TextView
                    android:id="@+id/tv_shortMovie_Selectright"
                    android:layout_width="fill_parent"
                    android:layout_height="45dip"
                    android:layout_weight="1"
                    android:background="@drawable/btn_bg_color_selector"
                    android:drawableLeft="@drawable/img_icon_random_filter"
                    android:gravity="center_vertical"
                    android:paddingLeft="30dip"
                    android:text="发现微电影"
                    android:textColor="#8f8f95"
                    android:textSize="16sp" />
            </LinearLayout>
        </RelativeLayout>

        <TextView
            android:id="@+id/tvLine_2"
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:layout_below="@+id/layout_filterBar"
            android:background="#C8C7CC" />

        <android.support.v4.view.ViewPager
            android:id="@+id/shortMovie_viewpager"
            android:layout_marginTop="0.5dp"
            android:layout_width="fill_parent"
            android:layout_height="180dip"
            android:layout_below="@+id/tvLine_2"
            android:background="#fff" />

        <LinearLayout
            android:id="@+id/shortMovie_viewGroup"
            android:layout_width="fill_parent"
            android:layout_height="35dip"
            android:layout_alignParentRight="true"
            android:layout_alignBottom="@+id/shortMovie_viewpager"
            android:background="@drawable/ic_transparent_content_title"
            android:gravity="center_vertical|right"
            android:orientation="horizontal"
            android:paddingRight="10dp" >
        </LinearLayout>

        <TextView
            android:id="@+id/filmName"
            android:layout_width="wrap_content"
            android:layout_height="35dp"
            android:layout_alignBottom="@+id/shortMovie_viewGroup"
            android:layout_alignParentLeft="true"
            android:gravity="center_vertical"
            android:text="一只狗的意愿"
            android:textColor="#fff"
            android:textSize="16sp" />

        <!-- 佳作推荐电影 -->

        <ImageView
            android:id="@+id/img_line_1"
            android:layout_width="3dip"
            android:layout_height="30dip"
            android:layout_below="@+id/shortMovie_viewGroup"
            android:layout_marginLeft="15dip"
            android:layout_marginTop="15dip"
            android:background="#f1a73c" />

        <TextView
            android:id="@+id/name_movieHeadLine_1"
            android:layout_width="wrap_content"
            android:layout_height="30dip"
            android:layout_below="@+id/shortMovie_viewGroup"
            android:layout_marginLeft="10dip"
            android:layout_marginTop="15dip"
            android:layout_toRightOf="@+id/img_line_1"
            android:gravity="center_vertical"
            android:text="佳作推荐"
            android:textSize="16sp" />

        <GridView
            android:id="@+id/item1_gridView_top"
            android:layout_width="fill_parent"
            android:layout_height="350dip"
            android:layout_below="@+id/img_line_1"
            android:layout_marginTop="5dip"
            android:cacheColorHint="#ffffff"
            android:listSelector="#ffffff"
            android:horizontalSpacing="5dip"
            android:transcriptMode="disabled"
            android:numColumns="3"
            android:scrollbars="none"
            android:verticalSpacing="20dip" />

        <!-- 国内电影 -->

        <ImageView
            android:id="@+id/img_line_2"
            android:layout_width="3dip"
            android:layout_height="30dip"
            android:layout_below="@+id/item1_gridView_top"
            android:layout_marginLeft="15dip"
            android:layout_marginTop="15dip"
            android:background="#f1a73c" />

        <TextView
            android:id="@+id/name_movieHeadLine_2"
            android:layout_width="wrap_content"
            android:layout_height="30dip"
            android:layout_below="@+id/item1_gridView_top"
            android:layout_marginLeft="10dip"
            android:layout_marginTop="15dip"
            android:layout_toRightOf="@+id/img_line_2"
            android:gravity="center_vertical"
            android:text="国内作品推荐"
            android:textSize="16sp" />

        <GridView
            android:id="@+id/item2_gridView_top"
            android:layout_width="fill_parent"
            android:layout_height="350dip"
            android:layout_below="@+id/img_line_2"
            android:layout_marginTop="5dip"
            android:cacheColorHint="#ffffff"
             android:listSelector="#ffffff"
            android:horizontalSpacing="5dip"
            android:transcriptMode="disabled"
            android:numColumns="3"
            android:scrollbars="none"
            android:verticalSpacing="20dip" />

        <!-- 国外电影 -->

        <ImageView
            android:id="@+id/img_line_3"
            android:layout_width="3dip"
            android:layout_height="30dip"
            android:layout_below="@+id/item2_gridView_top"
            android:layout_marginLeft="15dip"
            android:layout_marginTop="15dip"
            android:background="#f1a73c" />

        <TextView
            android:id="@+id/name_movieHeadLine_3"
            android:layout_width="wrap_content"
            android:layout_height="30dip"
            android:layout_below="@+id/item2_gridView_top"
            android:layout_marginLeft="10dip"
            android:layout_marginTop="15dip"
            android:layout_toRightOf="@+id/img_line_3"
            android:gravity="center_vertical"
            android:text="国外作品推荐"
            android:textSize="16sp" />

        <GridView
            android:id="@+id/item3_gridView_top"
            android:layout_width="fill_parent"
            android:layout_height="350dip"
            android:layout_below="@+id/img_line_3"
            android:layout_marginTop="5dip"
            android:cacheColorHint="#ffffff"
             android:listSelector="#ffffff"
            android:horizontalSpacing="5dip"
            android:transcriptMode="disabled"
            android:numColumns="3"
            android:scrollbars="none"
            android:verticalSpacing="20dip" />

    </RelativeLayout>

</ScrollView>

根部局是ScrollView,然后根部局中嵌套了一个TitleBar标题,其下面是一个ViewPager,然后再下面依次是三个GridView。

布局就是这样的,当我运行之后,页面显示结果不是整个页面从ScrollView的 y=0 位置显示。即:不是从顶部位置显示,而是冲ScrollView的中间部位展示该页面的所有内容;

解决办法:有人说使用方法:

mScrollView.smoothScrollTo(0, 0);

或者

mScrollView.scrollTo(0, 0);

但是经过我的测试使用,是不可以的。现有一个方法能解决:使用该布局最顶部的ScrollView中最顶部的那个控件View、layout都行,让后使用这几行代码使其获取焦点就行了;如下所示:

view.setFocusable(true);
view.setFocusableInTouchMode(true);
view.requestFocus();
时间: 2024-08-07 19:43:28

以ScrollView为根的部局,不能从顶部显示其包含的页面内容的相关文章

c++内存部局(虚继承)

最近又重新温习了一下深度探索c++对象模型,中虚拟继承虚表的实现,为了弄清虚表的内存部局情况特写此测试程序. 测试程序分别在windows vs2012下,与linux gcc 4..4.7 20120313 redhat4.4.7-4下 windows vs2012 上图中的偏移为-4表明存在vptr,如果为0说明没有vptr,下面的程序可以说明,而且从图中可以看出虚表中不会有重复的选项 #include <iostream> using namespace std; class X{ pu

flex部局 API

1. 要使用伸缩部局先要给 父元素设置为伸缩盒子 display:flex; 2. 伸缩盒子具有了主轴(默认水平从左向右) 伸缩盒子还有测轴(侧轴始终垂直于主轴) 伸缩盒子中所有的子元素都按照主轴的方向显示 3. 设置主轴方向 (默认值row) flex-direction:row; 从左向右 flex-direction:row-reverse; 从右向左 flex-direction:column; 从上向下 flex-direction:column-reverse; 从下向上 4. 设置

9.解决ScrollView与ListView共存时ListView高度无法完全显示的问题。

问题: ScrollView与ListView共存时,ListView会只显示一行,其它行无法显示. 解决方案: 重写ListView如下即可解决问题. /**解决ScorllView与ListView共存时,ListView只显示一行.不能完全显示的问题. * @author Caiyuan Huang * 2014-9-26 */ public class CustomListView extends ListView { public CustomListView(Context cont

解决ScrollView中嵌套Listview,Listview中嵌套Listview显示不完整和滑动冲突的问题

在一个滑动控件或者是布局里面,添加另外一个可以滑动的控件,通常会造成一些莫名其妙的问题.今天主要介绍在工作中遇到的,在ScrollView布局中嵌套Listview显示不正常,和在Listview中嵌套Listview的滑动冲突的问题. 1.ScrollView布局中嵌套Listview显示不正常的解决方案 目前来说,解决这个问题有好几种解决方案,这里只介绍其中两种比较简单易行的其中两种. (1)自定义一个Listview,继承自Listview,代码如下: public class ListV

C# XML 输出xml根节点下的直接(第一级)子节点的内容

1 xml文件内容 1 <?xml version="1.0" encoding="utf-8" ?> 2 <cultures> 3 4 <daojia> 5 <book> 6 <name> 道德经</name> 7 <author>老子</author> 8 </book> 9 <book> 10 <name> 文始真经</na

ScrollView里面添加ListView时,解决ListView的显示问题

在ScrollView里面添加ListView时,看了很多其他人的讲述,好像ListView只显示一条信息,为此简单新写了一个ListView控件,在布局文件里调用就可以了,代码如下: 1:ScrollViewWithListView.java 1 package com.ghp.view; 2 3 import android.widget.ListView; 4 5 /** 6 * 7 * @Description: scrollview中内嵌listview的简单实现 8 * 9 * @F

案例:ScrollView中嵌套ListView, 避免:1.ListView只显示首项,2.ScrollView会自动滚动到ListView的首项位置

1.布局文件 <LinearLayout android:focusable="true" android:focusableInTouchMode="true" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <extra.vi

97、进入ScrollView根布局页面,直接跳到页面底部,不能显示顶部内容

API使用:http://www.cnblogs.com/over140/archive/2011/01/27/1945964.html 以ScrollView为根的部局,不能从顶部显示其包含的页面内容:下面是我哦的解决方案. mScrollView.smoothScrollTo(0, 0); mScrollView.scrollTo(0, 0); 但是经过我的测试使用,是不可以的.现有一个方法能解决:使用该布局最顶部的ScrollView中最顶部的那个控件View.layout都行,让后使用这

GPS坐标换算为百度坐标

最近在做一个关于手机定位的小应用,需求是这样的,用户通过手机(Wp8)进行二维码扫描操作并且记录用户的当前位置,在PC上可以查看用户所在地图的位置,做法就是在用户扫描条码时,通过手机GPS获取当前在地图上的位置(采用百度静态地图,根据坐标直接生成图片)并将图片保存到数据库,PC端直接从数据库中读取并展示图片.问题是:生成的图片所呈现的位置与实际位置偏差太大.于是我开始踏上了寻找解决办法的道路. 首先我检测我的硬件设备是否定位准确,我用WP8手机内置的地图进行了当前位置定位,结果没有问题,说明我的