M.Dave
M.Dave

Reputation: 23

Scrollview Realigns textView

I have a blank activity which contains many text view so I want to use scrollview but whenever I use it the text views shift from their preassigned position to the top.Before adding ScrollView and After adding ScrollView here's the xml code

<?xml version="1.0" encoding="utf-8"?>


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

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="OFF"
    android:id="@+id/button"
    android:onClick="torchToggle"
    android:layout_below="@+id/textView"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="71dp"
    android:background="#cdc6c6" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="Torch"
    android:id="@+id/textView"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:textColor="#e8d9d9" />

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:id="@+id/textView2"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:textColor="#dacece"
    android:text="#Error In display" />

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:id="@+id/textView3"
    android:layout_below="@+id/textView2"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="83dp"
    android:textColor="#cdc0c0"
    android:text="#Error in display" />

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:id="@+id/textView4"
    android:textColor="#f3ef7a"
    android:layout_below="@+id/textView3"
    android:layout_centerHorizontal="true"
    android:text="#Error in display" />

<ProgressBar
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/progressBar"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true" />

<Button
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="next"
    android:id="@+id/button2"
    android:layout_alignTop="@+id/button"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:nestedScrollingEnabled="false"
    android:onClick="nextActivity" />



</RelativeLayout>
</ScrollView>

Upvotes: 0

Views: 24

Answers (1)

alex
alex

Reputation: 6409

The height of your RelativeLayout is falling back to wrap_content when inside the ScrollView as the virtual height of the ScrollView is infinite and match_parent doesn't make sense.

You could try adding android:fillViewport="true" to the ScrollView. This will give the RelativeLayout a minimum height of match_parent. You should change the RelativeLayout's layout_height to wrap_content.

Upvotes: 2

Related Questions