0

I have a problem to fill the whole screen with a scrollview.

How do I make the scrollview cover the whole screen width and screenheight? I tried with fillviewport but that that works for the screenheight.

I am not sure if its the scrollview or its parent (FrameLayout) that is the problem?

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:orientation="vertical" >

<ScrollView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:fillViewport="true">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >


 <ImageView
    android:id="@+id/img1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="img1"/>

 <TextView 
     android:id="@+id/text_img1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:visibility="gone"
     />

 <ImageView
    android:id="@+id/img2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="img2"/>

 <TextView 
     android:id="@+id/text_img2"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:visibility="gone"
    />

<ImageView
    android:id="@+id/img3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="img3"/>

 <TextView 
     android:id="@+id/text_img3"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:visibility="gone"
    />

    </LinearLayout>
</ScrollView>

java
  • 1,165
  • 1
  • 25
  • 50

3 Answers3

0

Change your <ScrollView> from wrap_content to match_parent.

Example:

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center">

Also, you should be using match_parent instead of fill_parent in API 8+.

EDIT:

After talking a bit in the comments, OP and I discovered that the FrameLayout's default background is transparent, which means you can see the old view underneath.

Using a LinearLayout or really anything instead of a FrameLayout will fix this problem.

Community
  • 1
  • 1
sonictt1
  • 2,906
  • 1
  • 15
  • 18
  • @java Interesting. Is there any particular reason why you're using a FrameLayout? Try changing it to a LinearLayout, or try setting a background color for the FrameLayout. – sonictt1 Dec 07 '15 at 21:46
  • Yes - you are correct, I have just been thinking of this. I'll try to change that (clumpsy of me - I can see now that Android Lint tells me the FrameLayout or ScrollView is useless. – java Dec 07 '15 at 21:53
  • @java Excellent! I'm glad I could help you figure this out. I'll update my answer and I would appreciate it if you could accept it as the correct one so that future developers who see this question will see that we found how to resolve it. :) – sonictt1 Dec 07 '15 at 21:54
  • Yes I will if it works, but the same warning if I use LinearLayout as parent – java Dec 07 '15 at 22:00
0

change your ScrollView and LinearLayout like this

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
Vasileios Pallas
  • 4,801
  • 4
  • 33
  • 50
0

Other answers are going in the right direction but your main problem is probably due to the fact that it's a Dialog.

First of all make sure your Dialog is borderless. You can use one of approaches proposed here (not to duplicate answers).

Community
  • 1
  • 1
Bartek Lipinski
  • 30,698
  • 10
  • 94
  • 132