Black Screen using ScrollView + RelativeLayout and

2019-09-14 07:28发布

问题:

I am trying to develop a block representation with inputs and outputs. The main ideia is:

  1. A user can add outputs/inputs
  2. A user can edit the ouputs/inputs added

So we have something like this:

I managed to build a dynamic canvas that changes when the user presses one of the buttons (the painted area grows).

The problem starts when the canvas is bigger than screen height. The result is something like this:

Notice that I have a scroll view. However it seems that scrollview puts everything in black. My xml file is something like this:

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true">
    <RelativeLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <pt.mypackage.BlockCanvas
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <EditText 
            ... />

        <Button
            ... />    

        <Button
            ... />    

    </RelativeLayout>
</ScrollView>

回答1:

I've experience something similar to your problem, I solved it by wrapping up the scroll view with RelativeLayout and using android:layout_allignParentTop="true". If doesnt work try adding empty view(no height just width) that will work as anchor to which your ScrollView will be placed below. I hope this makes sense and works