0

Here is my xml code i want to apply scrolling in View but no scroll appears in my device screen.Here is the XML Layout.Can someone please suggest me possible solutions to overcome on this situation.....

    <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/home_bg"
    android:orientation="vertical" >

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

        <ImageView
            android:id="@+id/askfatwa_header"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/askfatwa_top_bar" />
</LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/askfatwa_header"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_marginTop="5dp"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/name_askscreen"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/name"
                android:textColor="@android:color/white"
                android:textSize="20sp" />

            <EditText
                android:id="@+id/askscreen_name"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="3dp"
                android:paddingLeft="5dp"
                android:maxLines="1"
                android:inputType="text"

                android:background="@drawable/textfield" >
            </EditText>
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
             android:layout_marginTop="5dp"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/email_askscreen"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"

                android:text="@string/Email"
                android:textColor="@android:color/white"
                android:textSize="20sp" />

            <EditText
                android:id="@+id/askscreen_email"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="3dp"
                android:maxLines="1"
                android:inputType="textEmailAddress"
                  android:background="@drawable/textfield"
                android:paddingLeft="5dp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
             android:layout_marginTop="5dp"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/address_askscreen"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"

                android:text="@string/Address"
                android:textColor="@android:color/white"
                android:textSize="20sp" />

            <EditText
                android:id="@+id/askscreen_address"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="3dp"
                android:paddingLeft="5dp"
                android:inputType="textMultiLine"

                android:background="@drawable/textfield" />
        </LinearLayout>
        <!-- <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
             android:layout_marginTop="5dp"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/contact_askscreen"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/Contact"
                android:textColor="@android:color/white"
                android:textSize="20sp" />

            <EditText
                android:id="@+id/askscreen_contact"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="3dp"
                android:paddingLeft="5dp"
                  android:background="@drawable/textfield" />
        </LinearLayout> -->

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
             android:layout_marginTop="5dp"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/subject_askscreen"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/Subject"
                android:textColor="@android:color/white"
                android:textSize="20sp" />

            <!-- <EditText
                android:id="@+id/askscreen_subject"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="3dp"
                android:paddingLeft="5dp" /> -->
                <Spinner 
                android:id="@+id/askscreen_subject"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="3dp"
                android:paddingLeft="5dp"/>
        </LinearLayout>
         <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_marginTop="5dp"
            android:orientation="vertical" >

           <!--   <TextView
                android:id="@+id/body_askscreen"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:hint="Type Your Question"
                android:textColor="@android:color/white"
                android:textSize="20sp" />  -->

            <EditText
                android:id="@+id/askscreen_question"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="3dp"
                android:background="@drawable/textfield"
                android:hint="Type Your Question"
                android:minLines="1"
                android:inputType="textMultiLine"
                android:minHeight="8dp"
                android:minWidth="10dp"
                android:lines="15"
                android:paddingLeft="5dp" />

        </LinearLayout>


        <ImageView
            android:id="@+id/askscreen_submit_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="10dp"
            android:paddingTop="20dp"
            android:src="@drawable/askftwa_submit_button" />
    </LinearLayout>

</ScrollView>
3
  • You have a lot of unnecessary LinearLayouts, you should try to make this lighter, for both performances and readability's sake ...
    – 2Dee
    Feb 7, 2014 at 20:11
  • @2Dee can u please edit code and write correct code here Feb 7, 2014 at 20:13
  • I could but I would prefer for you to try and correct it yourself, then ask if you have problems, otherwise you will not learn. "Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." Try to follow Lint warnings, for example your IDE should highlight the fact that the LinearLayout containing askfatwa_header is completely useless because it has only one child. If you really want your code reviewed, try codereview.stackexchange.com
    – 2Dee
    Feb 7, 2014 at 20:19

2 Answers 2

0

Add more elements and the scroll will appear. Right now all the elements are fitting within the screen and that's why you don't see any scroll

2
  • no when my keyboard appears one of my textbox is hidden and its not scrolling Feb 7, 2014 at 18:41
  • @user3233280 Try adding the property android:windowSoftInputMode="adjustResize" in the manifest Feb 7, 2014 at 18:46
0
First a fall by seeing your xml, you are creating very expensive layout containing 
unnecessarily many Linear layouts ie when orientation of your all views are vertical.    
Why are you defining your views like textbox and edittext in separate Linear Layouts, 
it creates performance issues.

Secondly, you should not define set any background and orientation in scroll view.
By default orientation of scroll view is vertical.

Although i just run your code with few changes and its working fine on my emulator 
and on my device.



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

    // This is Main layout which contains all your child view 

    <LinearLayout
      android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:background="@drawable/home_bg"
     android:orientation="vertical"  >

     // Define your remaining child views here.....
     // And as i can see all views are oriented vertically, so you can define all view 
        inside this Main Layout itself.
    //  Accordingly you can set Margins of your views too.  


   </LinearLayout>

 </ScrollView>
7
  • can u please check is it scroolable with image still its not scrollable i am providing u image Feb 7, 2014 at 20:30
  • Have you tried inserting more views in your xml. Why dont you just add few more images views in your xml. You will definetly got to know that whether your layout is scrolling or not....
    – A.R.
    Feb 7, 2014 at 20:51
  • yes i have inserted more view in it but its not scrolling while same code i have inserted in somewhere else this is scrolling Feb 7, 2014 at 20:52
  • If you know that your xml code is working fine in another xml, why dont you just try replacing that working xml with the xml which is not scrolling.
    – A.R.
    Feb 7, 2014 at 21:01
  • yes when i am making another sample project with my required xml its scrolling while when trying to put same xml in my Current project folder and using it its not scrolling can u please help me ? Feb 8, 2014 at 8:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.