Android scrollview hiding top content in layout

前端 未结 5 668
花落未央
花落未央 2020-12-05 17:34

Im having a problem where the android scrollview starts hiding a pair of textviews I have at the top of my layout, I have found another person on this very site who had that

相关标签:
5条回答
  • 2020-12-05 17:35

    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);
            }
        });
    }
    
    0 讨论(0)
  • 2020-12-05 17:36

    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" >
    
    0 讨论(0)
  • 2020-12-05 17:37

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

    0 讨论(0)
  • 2020-12-05 17:48

    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.

    0 讨论(0)
  • 2020-12-05 18:01

    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" >
    
    0 讨论(0)
提交回复
热议问题