ScrollView doesn't display its content properly in lower versions of android
Asked Answered
A

4

6

You can see my scrollview being displayed the same in jellybean, & kitkat, very awesome:

one enter image description here

But I am shocked to see the same thing in lower versions like 2.2, 2.3.3

enter image description here enter image description here

It seems that it display some portion of text attached to upper & bottom portion of screen.

BTW, The lines in middle are just the textviews with gray background .

You can see my xml code, sorry its a little long code

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/stars"
android:padding="5dp"
android:scrollbars="vertical"
>


<LinearLayout


android:layout_width="match_parent"
android:layout_height="wrap_content"
        android:orientation="vertical" >

 <EditText
     android:id="@+id/editText1"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:ems="10"
     android:textColor="#fff"
     android:hint="Type your Full Name here"
     android:inputType="textPersonName"
     android:digits="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz " >

     <requestFocus />
 </EditText>

 <Button
     android:id="@+id/button1"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:gravity="center"
     android:background="#330000"
     android:onClick="showresult"
     android:textColor="#ffffff"
     android:alpha=".8"
     android:text="Show My Fortune" />

 <TextView
     android:id="@+id/textView13"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:textColor="#ffffff"
     android:textAppearance="?android:attr/textAppearanceSmall" />

 <LinearLayout
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:orientation="horizontal" 
     android:baselineAligned="false">

     <LinearLayout
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_weight="1" 
         android:orientation="horizontal"
         >

         <TextView
             android:id="@+id/textView1"
             android:layout_width="20dp"
             android:layout_height="wrap_content"
             android:textColor="#ffffff"
             android:textSize="18sp"
              />

         <TextView
             android:id="@+id/textView2"
             android:layout_width="50dp"
             android:layout_height="wrap_content"

             android:textColor="#ffffff"
             android:textSize="18sp" />
     </LinearLayout>

     <LinearLayout
         android:layout_width="wrap_content"
         android:layout_height="wrap_content" 
         android:orientation="horizontal"
         android:layout_weight="1" >

         <TextView
             android:id="@+id/textView3"
             android:layout_width="20dp"
             android:layout_height="wrap_content"

             android:textColor="#ffffff"
             android:textSize="18sp" />

         <TextView
             android:id="@+id/textView4"
             android:layout_width="50dp"
             android:layout_height="wrap_content"

             android:textColor="#ffffff"
             android:textSize="18sp" />
     </LinearLayout>

     <LinearLayout
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:orientation="horizontal"
         android:layout_weight="1"  >

         <TextView
             android:id="@+id/textView5"
             android:layout_width="20dp"
             android:layout_height="wrap_content"
             android:textColor="#ffffff"
             android:textSize="18sp"/>

         <TextView
             android:id="@+id/textView6"
             android:layout_width="50dp"
             android:layout_height="wrap_content"
             android:textColor="#ffffff"
             android:textSize="18sp" />
     </LinearLayout>

 </LinearLayout>

 <TextView
     android:id="@+id/textView7"
     android:layout_width="match_parent"
     android:layout_height=".5dp"

     android:textAppearance="?android:attr/textAppearanceSmall" />

 <TextView
     android:id="@+id/textView8"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
      android:textColor="#ffffff"
     android:textAppearance="?android:attr/textAppearanceSmall" />

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

     <TextView
         android:id="@+id/textView9"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:textAppearance="?android:attr/textAppearanceLarge"
         android:textColor="#ffffff" />

     <TextView
         android:id="@+id/textView14"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:textColor="#ffffff"
         android:gravity="right"

         android:textAppearance="?android:attr/textAppearanceLarge" />

 </LinearLayout>

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

     <TextView
         android:id="@+id/textView10"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:textAppearance="?android:attr/textAppearanceLarge"
         android:textColor="#ffffff" />

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

         android:textColor="#ffffff"

         android:gravity="right"
         android:textAppearance="?android:attr/textAppearanceLarge" />

 </LinearLayout>

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

     <TextView
         android:id="@+id/textView11"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:textAppearance="?android:attr/textAppearanceLarge"
         android:textColor="#ffffff" />

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

         android:textColor="#ffffff"

         android:gravity="right"
         android:textAppearance="?android:attr/textAppearanceLarge" />

 </LinearLayout>

 <TextView
     android:id="@+id/textView12"
     android:layout_width="match_parent"
     android:layout_height=".5dp"/>

 <LinearLayout
     android:layout_width="match_parent"
     android:layout_height="wrap_content" 
     android:orientation="horizontal">

     <TextView
         android:id="@+id/textView17"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:textColor="#ffffff" 
         android:textAppearance="?android:attr/textAppearanceLarge" />

     <TextView
         android:id="@+id/textView18"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:gravity="right"
         android:textColor="#ffffff"
         android:textAppearance="?android:attr/textAppearanceLarge" />

 </LinearLayout>

 <TextView
     android:id="@+id/textView19"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:textColor="#ffffff"
     android:textAppearance="?android:attr/textAppearanceSmall" />

 <TextView
     android:id="@+id/textView20"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:textColor="#ff0000"
     android:textAppearance="?android:attr/textAppearanceLarge" />

 <LinearLayout
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:orientation="horizontal" >

     <TextView
         android:id="@+id/textView21"
         android:layout_width="40dp"
         android:layout_height="wrap_content"

         android:gravity="right"
         android:textColor="#ff0000"
         android:textAppearance="?android:attr/textAppearanceLarge" />

     <TextView
         android:id="@+id/textView27"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:textColor="#ffffff"
         android:textAppearance="?android:attr/textAppearanceLarge" />

     <TextView
         android:id="@+id/textView22"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:textColor="#ffff00"
         android:textAppearance="?android:attr/textAppearanceLarge" />

 </LinearLayout>

 <LinearLayout
     android:layout_width="wrap_content"
     android:layout_height="match_parent"
     android:orientation="horizontal" >

     <TextView
         android:id="@+id/textView23"
         android:layout_width="40dp"
         android:layout_height="wrap_content"
         android:textColor="#ff0000"
         android:gravity="right"
         android:textAppearance="?android:attr/textAppearanceLarge" />

     <TextView
         android:id="@+id/textView28"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:textColor="#ffffff"
         android:textAppearance="?android:attr/textAppearanceLarge" />

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

         android:textColor="#ffff00"
         android:textAppearance="?android:attr/textAppearanceLarge" />

 </LinearLayout>

 <LinearLayout
     android:layout_width="match_parent"
     android:layout_height="wrap_content" 
     android:orientation="horizontal">

     <TextView
         android:id="@+id/textView25"
         android:layout_width="40dp"
         android:layout_height="wrap_content"
         android:gravity="right"
         android:textColor="#ff0000"
         android:textAppearance="?android:attr/textAppearanceLarge" />

     <TextView
         android:id="@+id/textView29"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:textColor="#ffffff"
         android:textAppearance="?android:attr/textAppearanceLarge" />

     <TextView
         android:id="@+id/textView26"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:textColor="#ffff00"
         android:textAppearance="?android:attr/textAppearanceLarge" />

 </LinearLayout>

</LinearLayout>
</ScrollView>

Also in GraphicalLayout is shows this warning :enter image description here

I hope I explained my problem clearly !

Looking for a answer,

Thanks in advance


UPDATE: After @semsamot answer the above warning was disappeared, but the problem is still not solved.

Sorry, my above code was too long but I have another layout in my app displaying the same problem

Consider this code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/stars"
tools:context="com.vivekwarde.numerologyfortune.MyLuckyNumber"
>
<ScrollView 
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" >

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

        <Button
            android:id="@+id/button1"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:textColor="#fff"
            android:gravity="center"
            android:onClick="showDatePickerDialog"
            android:text="Birthdate ?"
            android:background="#4c0000" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
            android:textColor="#ffffff"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Large Text"
            android:textColor="#ffffff"
            android:textAppearance="?android:attr/textAppearanceLarge" />

    </LinearLayout>

</ScrollView>
</RelativeLayout>

If I display this layout simply it displays as expected in jelly bean & kitkat like thisenter image description here

But see this output in 2.2 & 2.3.3 enter image description here

Why the text in TextView does not display properly as expected. ?

Appearance answered 5/8, 2014 at 13:8 Comment(9)
Do you get this behavior on a particular device?Placatory
Yes this behaviour is there in spice mi-270 (v2.2), also I see this behaviour in emulators 2.2 & 2.3.3 !Appearance
Can you try with this: <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="vertical" >Goldwin
@SimonMarquis The same problem exists though I tried what u said !Appearance
It could be that the button is overlaps the textarea. If i was you i would check if that is the caseTreillage
Ya i thought the same but what can i doAppearance
Are you aware of the current share of android versions? developer.android.com/about/dashboards/… 2.2 is 0.7%, 2.3 is 13.6% and of course they get less every day. Just saying as you might decide it's not worth the effort or worry to support a diminishing percentage, currently 14.3%.Psalmody
Just using the percentage in the opposite direction, 14.3% means a relevant amount of users for some of us.Nuts
Issue filed to android here code.google.com/p/android/issues/detail?id=76453Appearance
Z
4

Don't use float values that lower than 1 in this format: ".x" Instead use this format: "0.x"

If you change those values you see the warnings disappear!

Note: Also note that "alpha" attribute introduced in API Level 11 so it will not work in lower API(s).

Zabrze answered 9/8, 2014 at 18:55 Comment(1)
After following your answer, warnings were disappeared, I am facing the same problem in lower versions ! Thanks thoughAppearance
G
1

I don't think it'll work but u should try it once.

instead of using android:layout_height="60dp" use maxHeight and minHeight with same value 60dp as ur case .I think it will solve your problem.And also fill some background color to see whats wrong with the soln.

Gussi answered 18/8, 2014 at 5:42 Comment(5)
U mean to say inside button?Appearance
Its giving me java.lang.RuntimeException button should have layout_height attributeAppearance
You must have layout_height attrib but having value wrap content.Gussi
Still the same problemAppearance
can you share any file or demo using drive or dropbox on which we can add some.Gussi
F
0

Don't use wrap_content for the ScrollView. The ScrollView should have a concrete size which is relate with the screen size, not the content. The LinearLayout inside it should keep the wrap_content. In both your examples, you should use match_parent for the ScrollView

Frans answered 14/8, 2014 at 18:8 Comment(0)
V
0

don`t use .5dp while setting height or width

<TextView
 android:id="@+id/textView7"
 android:layout_width="match_parent"
 android:layout_height=".5dp"  //  **modify** this to android:layout_height="1dp"
 android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
 android:id="@+id/textView12"
 android:layout_width="match_parent"
 android:layout_height=".5dp"  //  **modify** this to android:layout_height="1dp" />

Using this you can remove this error requestfocus does not set the required layout_height attribute and also might be you can solve your issue also

Vagrancy answered 22/8, 2014 at 7:29 Comment(1)
This answer was already posted, & BTW the problem is something elseAppearance

© 2022 - 2024 — McMap. All rights reserved.