android Scrollview裡的內容不停留在頂部的問題
阿新 • • 發佈:2019-02-14
先說明一下:任何一個頁面都應該按照佈局的先後順序來顯示,我這出現的問題就是,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>