您的位置:首页 > 移动开发 > Android开发

Android ScrollView嵌套Viewpager嵌套ListView切换时到顶部或位置改变问题解决

2017-03-21 13:13 736 查看

Android ScrollView嵌套Viewpager嵌套ListView切换时到顶部或位置改变问题解决

好了,思想+代码

Activity:

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


Activity时,将Scrollview下面的LinearLayout里添加以上两个属性就可以。

例:

 <ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:focusable="true" android:focusableInTouchMode="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="183dp">
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="183dp"
android:layout_centerInParent="true">
</android.support.v4.view.ViewPager>
......省略


Fragment:

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


在Fragment里面,除了将这个和Activity里面一样外,还要在代码里面添加listview.setFocusable(false);这个属性。

例:

protected void setOnPageSelected(int position) {
if (position==0){
if (list!=null)
list.setFocusable(false);               thisText.setTextColor(getResources().getColor(R.color.black_gray));
one.setTextColor(getResources().getColor(R.color.red));
thisText=one;
}
......省略


这样做的原因是让listview的父类抢到焦点,不能listview获取到焦点然后改变位置。

本文为个人原创,如有误解和错误请指教,谢谢,如需转载,请注明出处,http://blog.csdn.net/aierJun/article/details/64440476 谢谢。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐