Android scrollview hiding top content in layout

a 夏天 提交于 2019-11-27 21:49:07

Found it ! It's the android:layout_gravity="center" in the LinearLayout that is the culprit. Just delete this and everything should be fine.

Have you tried setting

android:fillViewport="true"

in the ScrollView?

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:fillViewport="true"
  android:background="@color/title_color_dark_transparent" >

You can scroll programmatically.

  1. Remove android:layout_gravity property from xml
  2. Add scrolling to onResume function

Some code from my project:

protected void onResume() {
    super.onResume();
    final HorizontalScrollView svInMenu = (HorizontalScrollView) findViewById(R.id.svInMenu);
    ViewTreeObserver vto = svInMenu.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        public void onGlobalLayout() {
            svInMenu.scrollTo(svInMenu.getRight() / 4, 0);
        }
    });
}

Your outer LinearLayout has its height set to match_parent. It should be wrap_content instead. The inner LinearLayout should also have height wrap_content.

Add android:layout_weight="1" to your scrollview. It will resolve the problem. Something like this

 <ScrollView
        android:id="@+id/scroll"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_weight="1" >
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!