android 中的 scrollView 控件的默认位置和子控件的焦点冲突
2015-06-08 22:50
721 查看
最近在开发 dribbble 客户端, 遇到一个这样的问题。
在 scrollView 控件中,如果有子控件一开始就获得焦点,例如设置了
或者设置了
那么当 scrollView 第一次出现的时候,scrollView 会默认滑动到获得焦点的子控件位置,
为了修正这个问题,应该在 scrollView 控件的第一个子控件设置如下属性
布局文件
在 scrollView 控件中,如果有子控件一开始就获得焦点,例如设置了
android:focusable="true"
或者设置了
android:textIsSelectable="true"
那么当 scrollView 第一次出现的时候,scrollView 会默认滑动到获得焦点的子控件位置,
为了修正这个问题,应该在 scrollView 控件的第一个子控件设置如下属性
android:focusable="true" android:focusableInTouchMode="true" android:descendantFocusability="beforeDescendants"
布局文件
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
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"
>
<ImageView
android:id="@+id/shot_imageview"
android:layout_width="match_parent"
android:layout_height="200dp"
android:src="@drawable/shot_empty"
android:focusable="true" android:focusableInTouchMode="true" android:descendantFocusability="beforeDescendants"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/activity_vertical_margin"
>
<ImageView
android:id="@+id/user_imageview"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/shot_empty"
android:layout_marginRight="8dp"
/>
<TextView
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/user_imageview"
android:layout_marginBottom="8dp"
android:text="Jon Ivy"/>
<ImageView
android:id="@+id/view_imageview"
android:layout_width="@dimen/shot_count"
android:layout_height="@dimen/shot_count"
android:layout_toRightOf="@+id/user_imageview"
android:layout_below="@+id/username"
android:src="@mipmap/view_off"
android:layout_marginRight="6dp"
/>
<TextView
android:id="@+id/view_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/view_imageview"
android:layout_below="@+id/username"
android:text="999"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/activity_vertical_margin"
>
<LinearLayout
android:id="@+id/comment"
style="@style/count_style"
>
<ImageView
android:layout_width="@dimen/shot_count"
android:layout_height="@dimen/shot_count"
android:padding="3dp"
android:src="@mipmap/comment_off"
/>
<TextView
android:id="@+id/comment_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="999"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/like"
style="@style/count_style"
>
<ImageView
android:layout_width="@dimen/shot_count"
android:layout_height="@dimen/shot_count"
android:padding="3dp"
android:src="@mipmap/like"
/>
<TextView
android:id="@+id/like_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="999"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/bucket"
style="@style/count_style"
>
<ImageView
android:layout_width="@dimen/shot_count"
android:layout_height="@dimen/shot_count"
android:src="@mipmap/bucket"
android:padding="3dp"
/>
<TextView
android:id="@+id/bucket_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="999"
/>
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/descript_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/activity_vertical_margin"
android:textIsSelectable="true"
/>
</LinearLayout>
</ScrollView>
相关文章推荐
- ScrollView滚动条颜色的设置方法
- 刷新Activity中的scrollview示例(局部ui刷新)
- Android之ScrollView嵌套ListView和GridView冲突的解决方法
- android 实现ScrollView自动滚动的实例代码
- Android中实现监听ScrollView滑动事件
- Android ScrollView使用代码示例
- 开源中国 OsChina Android 客户端源码分析(3)可以拖拽的ScrollView
- 安卓布局应用学习代码附带效果图
- 在ScrollView中嵌套ListView时,ListView只能显示一行多一点
- 在ScrollView中使用pinch实现图片的缩放
- 关于父view拦截触屏事件
- 简单的重写ScrollView
- 初识ScrollView
- ScrollView 完整截图实现
- iOS中ScrollView的属性和方法详解
- IOS中UIScrollView的属性和委托方法
- 如何让scrollView拥有单方向的bounce
- ScrollView 内部嵌套 ListView +复杂布局 设置页面全屏滑动
- android 小水滴变成大江河
- ScrollView的Holder效果