-2

I am having problem in attaching fragment to RelativeLayout when the RelativeLayout has been put inside ScrollView. Please see the xml code belove -

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:obs="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#ffffff" 
    android:orientation="vertical">

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

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="48dp" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:textColor="#9982d6"
            android:textSize="20sp" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="2dp"
            android:layout_marginTop="10dp"
            android:gravity="center_vertical"
            android:textColor="#9982d6"
            android:textSize="20sp"/>
    </RelativeLayout>

    <View
        android:id="@+id/topDivider2"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#9982d6"
        />

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:textColor="#848484"
            android:textSize="14sp" />

        <View
            android:layout_width="match_parent"
            android:layout_height="3.5dp"
            android:layout_alignParentBottom="true"
            android:background="#4ccdd9"
            android:visibility="gone" />

        <View
            android:layout_width="5dp"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            android:layout_marginBottom="4dp"
            android:layout_marginTop="4dp" />
    </RelativeLayout>

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:dividerHeight="0dp" />

</LinearLayout>

</ScrollView>

In above xml code I have to attach a fragment inside RelativeLayout GraphContainer which is not working. Attaching fragment works if I don't use ScrollView. Please help...

aaaaa
  • 449
  • 1
  • 5
  • 18

3 Answers3

0

Add android:fillViewport property to scroll view . It will work!!

as

  <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:obs="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:fillViewport="true" >

//===== furter code
Amarjit
  • 4,327
  • 2
  • 34
  • 51
  • I tried it but it's showing error- No resource identifier found for attribute 'fillViewPort' in package 'android' – aaaaa Mar 27 '15 at 12:52
  • 1
    use this android:fillViewport="true" make "P" of port to small – Amarjit Mar 27 '15 at 12:55
  • poor is right for android:fillViewport="true" and android:layout_height=”match_parent” for scroll view means “set the height to the height of the parent.” This is obviously not what you want when using a ScrollView. After all, the ScrollView would become useless if its content was always as tall as itself. – Hulk Mar 27 '15 at 13:10
  • android:fillViewport="true" is not working in my case. – aaaaa Mar 30 '15 at 04:25
0

Try using the scrollview inside a layout that covers the whole activity.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="any_bg_color">


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

//other layouts and views here

 </ScrollView>
</RelativeLayout>
Niraj Niroula
  • 2,376
  • 1
  • 17
  • 36
0

If you want your fragment scrollable than remove ScrollView from this xml and put it in your fragment's xml. Also I can see you have defined a ListView inside ScrollView, it will not work this way as ListView has its own ScrollView.

Prashant Patel
  • 1,087
  • 11
  • 18