ScrollView does not display its contents properly in lower versions of Android

You can see that my scrollview displays the same in jellybean, and kitkat is very cool:

oneenter image description here

But I'm shocked to see the same thing in lower versions, such as 2.2, 2.3.3

enter image description hereenter image description here

It seems to display a piece of text attached to the top and bottom of the screen.

BTW, the lines in the middle are just text images with a gray background.

You can see my xml code, sorry its a bit 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> 

GraphicalLayout also shows this warning: enter image description here

Hope I clearly explained my problem!

Looking for an answer

Thank you in advance


UPDATE . After @semsamot answered, the warning was gone, but the problem is still not resolved.

Sorry, my code above is too long, but I have a different layout in my application 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 show this layout, it will display as expected in a jelly bean and kitkat, like this enter image description here

But see this conclusion in 2.2 and 2.3.3 enter image description here

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

+6
source share
4 answers

Do not use float values โ€‹โ€‹that are less than 1 in this format: ".x" Use this format instead: "0.x"

If you change these values, you will see that the warnings have disappeared!

Note: Also note that the alpha attribute, introduced at API level 11, will therefore not work in lower APIs (s).

+3
source

I don't think this will work, but I have to try it once.

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

+1
source

Do not use wrap_content for ScrollView. ScrollView should have a specific size, which is related to the size of the screen, not the content. LinearLayout inside it should contain wrap_content. In both examples you should use match_parent for ScrollView

0
source

Do not use .5dp when 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" /> 

With this feature you can remove this error requestfocus does not set the required layout_height attribute , and maybe you can also solve your problem

0
source

Source: https://habr.com/ru/post/973369/


All Articles