scrollview 的一个大问题

xiaoru5127 2015-01-06 02:56:45
今天在用scrollview的时候 发现 scrollview里面包含的LinearLayout如果高度不超过屏幕 那么一切正常也不需要scrollview就是了。但是超过了之后会发现 LinearLayout内部最顶部的内容会显示不出来 数据那些都有在就是显示不出来 拉也拉不上去。

布局代码如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/task_item_daijiedan_top"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#37a8c8"
>
<ImageView
android:id="@+id/task_item_daijiedan_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:src="@drawable/back"
android:layout_alignParentLeft="true"
/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
/>

</RelativeLayout>


<ScrollView
android:id="@+id/task_item_zbrw_scrollview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="50dp"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
>

<include
android:id="@+id/task_item_zbrw_info"
layout="@layout/task_item_taskinfo" />
<LinearLayout
android:background="#eeeeee"
android:layout_width="fill_parent"
android:layout_height="2dp"/>



<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text:"/>
<com.oa.view.TextProgressBar
android:id="@+id/task_item_zbrw_progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/task_item_zbrw_renwufenpei"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test"
android:layout_centerInParent="true"
android:padding="10dp"
android:layout_margin="5dp"
android:background="@drawable/round_box"/>

</RelativeLayout>
<LinearLayout
android:background="#eeeeee"
android:layout_width="fill_parent"
android:layout_height="1dp"/>


<LinearLayout
android:id="@+id/task_item_zbrw_itemtask"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
/>

<LinearLayout
android:background="#eeeeee"
android:layout_width="fill_parent"
android:layout_height="2dp"/>



<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="test:"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:background="#eeeeee"/>

<LinearLayout
android:id="@+id/task_item_zbrw_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
/>


<LinearLayout
android:background="#eeeeee"
android:layout_width="fill_parent"
android:layout_height="2dp"/>



<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="test:"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:background="#eeeeee"/>

<LinearLayout
android:id="@+id/task_item_zbrw_attach"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
/>
</LinearLayout>
</ScrollView>

</LinearLayout>



<LinearLayout
android:id="@+id/task_item_zbrw_bottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:background="#d9d9d9"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/task_item_zbrw_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/add"
android:padding="5dp"
android:layout_margin="2dp"
android:layout_gravity="center"
android:gravity="center"
android:layout_weight="0.05"/>
<EditText
android:id="@+id/task_item_zbrw_et_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="@+id/task_item_zbrw_jindu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="进度"
android:padding="10dp"
android:layout_margin="2dp"
android:layout_gravity="center"
android:gravity="center"
android:background="@drawable/round_null_box"
android:layout_weight="0.001"
/>
<Button
android:id="@+id/task_item_zbrw_submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test"
android:background="@drawable/round_null_box"
android:padding="10dp"
android:layout_margin="2dp"
android:layout_gravity="center"
android:gravity="center"
android:layout_weight="0.001"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/task_item_zbrw_switchcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:visibility="gone"
android:padding="20dp"
>
<ImageView
android:id="@+id/task_item_zbrw_file"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/get_file"
android:layout_weight="1"/>
<ImageView
android:id="@+id/task_item_zbrw_photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/get_photo"
android:layout_weight="1"/>
<ImageView
android:id="@+id/task_item_zbrw_record"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/get_audio"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
...全文
178 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
brvel 2015-01-08
  • 打赏
  • 举报
回复
碰到过这个,用的是1楼的办法,也可以让其他有获取焦点的控件,失去焦点,setFocusable(false)
水的川 2015-01-06
  • 打赏
  • 举报
回复
这当然了,你scrollview又没有包含所有布局,然后进入页面以后首先焦点会聚焦到scrollview上,然后你scrollview中的内容刚好又充满了整个屏幕,所以造成了这个问题,建议将scrollview覆盖所有布局。
Jing丶無雙 2015-01-06
  • 打赏
  • 举报
回复
加个这个试试mScrollView.smoothScrollTo(0,0);

80,492

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧