简体   繁体   English

在较低版本的android中,ScrollView无法正确显示其内容

[英]ScrollView doesn't display its content properly in lower versions of android

You can see my scrollview being displayed the same in jellybean, & kitkat, very awesome: 您可以看到我的scrollview在jellybean和kitkat中显示相同,非常棒:

一在此输入图像描述

But I am shocked to see the same thing in lower versions like 2.2, 2.3.3 但是我很震惊地看到2.2,2.3.3等较低版本中的相同内容

在此输入图像描述在此输入图像描述

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 你可以看到我的xml代码,抱歉它有点长代码

<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 : 同样在GraphicalLayout中显示此警告: 在此输入图像描述

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. 更新 :@semsamot回答后上面的警告消失了,但问题仍未解决。

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 this 如果我显示这个布局,它就像在预期的那样在jelly bean和kitkat中显示 在此输入图像描述

But see this output in 2.2 & 2.3.3 但请参阅2.2和2.3.3中的此输出 在此输入图像描述

Why the text in TextView does not display properly as expected. 为什么TextView中的文本无法按预期正确显示。 ?

Don't use float values that lower than 1 in this format: ".x" Instead use this format: "0.x" 请勿以此格式使用小于1的浮点值:“。x”而是使用以下格式:“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). 注意:另请注意API级别11中引入的“alpha”属性,因此它不适用于较低的API。

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. 而不是使用android:layout_height="60dp"使用maxHeightminHeight使用相同的值60dp作为你的情况。我认为它将解决你的问题。并且还填充一些背景颜色来查看soln的错误。

Don't use wrap_content for the ScrollView. 不要对ScrollView使用wrap_content。 The ScrollView should have a concrete size which is relate with the screen size, not the content. ScrollView应具有与屏幕大小相关的具体大小,而不是内容。 The LinearLayout inside it should keep the wrap_content. 其中的LinearLayout应该保留wrap_content。 In both your examples, you should use match_parent for the ScrollView 在两个示例中,您应该对ScrollView使用match_parent

don`t use .5dp while setting height or width 在设置高度或宽度时不要使用.5dp

 <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 使用这个你可以删除这个错误请求focus没有设置所需的layout_height属性也可能你也可以解决你的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM