android Scrollview里的内容不停留在顶部的问题

来源:互联网 发布:招商迪辰软件 编辑:程序博客网 时间:2024/04/29 04:34


先说明一下:任何一个页面都应该按照布局的先后顺序来显示,我这出现的问题就是,Scrollview里面嵌套Listview的头布局一进来看不见了,直接被Listview把焦点给抢了。最先显示的是Listview的item部分。直接上图

解决代码在父布局里设置2个属性

android:focusable="true"android:focusableInTouchMode="true"



<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    tools:context="com.kyhh.youngworld.main.classification.activity.BrandListingActivity">    <include layout="@layout/system_titlebar_layouot" />    <com.kyhh.youngworld.widget.StickScrollView        android:layout_width="match_parent"        android:layout_height="match_parent">        <LinearLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:orientation="vertical"><!--这是包裹Listview头布局的父布局,在这里添加属性-->
            <RelativeLayout                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:focusable="true"                android:focusableInTouchMode="true">                <ImageView                    android:layout_width="match_parent"                    android:layout_height="@dimen/length_200"                    android:src="@color/textgray2" />                <LinearLayout                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:layout_centerInParent="true"                    android:gravity="center"                    android:orientation="vertical">                    <TextView                        android:id="@+id/brandlist_tv_attention"                        android:layout_width="wrap_content"                        android:layout_height="wrap_content"                        android:background="@drawable/btn_pressed"                        android:clickable="true"                        android:padding="5dp"                        android:text="关注"                        android:textSize="18sp" />                    <TextView                        android:id="@+id/brandlist_tv_attentioncount"                        android:layout_width="wrap_content"                        android:layout_height="wrap_content"                        android:layout_marginTop="10dp"                        android:text="关注人数" />                </LinearLayout>            </RelativeLayout>            <RelativeLayout                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:background="@drawable/btn_pressed"                android:gravity="center_vertical"                android:orientation="horizontal"                android:padding="10dp"                android:tag="sticky">                <TextView                    android:id="@+id/brandlist_tv_integration"                    android:layout_width="wrap_content"                    android:layout_height="match_parent"                    android:layout_marginLeft="12dp"                    android:background="@drawable/btn_pressed"                    android:gravity="center"                    android:padding="5dp"                    android:text="综合排序" />                <TextView                    android:id="@+id/brandlist_tv_sales"                    android:layout_width="wrap_content"                    android:layout_height="match_parent"                    android:layout_centerInParent="true"                    android:background="@drawable/btn_pressed"                    android:gravity="center"                    android:padding="5dp"                    android:text="销量" />                <TextView                    android:id="@+id/brandlist_tv_price"                    android:layout_width="wrap_content"                    android:layout_height="match_parent"                    android:layout_alignParentRight="true"                    android:layout_marginRight="12dp"                    android:background="@drawable/btn_pressed"                    android:gravity="center"                    android:padding="5dp"                    android:text="价格" />            </RelativeLayout>            <com.kyhh.youngworld.widget.NoScrollListview                android:id="@+id/brandlist_xrc_goodslist"                android:layout_width="match_parent"                android:layout_height="match_parent">            </com.kyhh.youngworld.widget.NoScrollListview>        </LinearLayout>    </com.kyhh.youngworld.widget.StickScrollView></LinearLayout>


1 0
原创粉丝点击