2013-04-02 86 views
4

我是Android新手 -Android滚动视图太长

我在屏幕上放置了滚动视图,只是在其中放置了一些文本。我这样做是因为在某些电话上,文字从屏幕上跑出来。

我遇到的问题是,我已经掉到页面上的滚动视图比它保存的内容更长 - 手机屏幕越窄,滚动视图越长。

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

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/app_background" 
    android:orientation="vertical" 
    android:padding="10dp" > 

    <EditText 
     android:id="@+id/editText1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:ems="20" 
     android:inputType="textMultiLine" 
     android:lineSpacingExtra="3dp" 
     android:text="Get ready to melt fat and burn calories with Fit Body Boot Camp&apos;s 14 Day Fat Furnace Workout Program! This is a detailed 14 Day Workout plan based on Fit Body Boot Camp&apos;s Unstoppable Fitness Formula that has been implemented in close to 300 boot camps worldwide by hundreds of thousands of clients who made the decision to lose weight and get healthier." 
     android:textColor="#FFF" 
     android:textColorLink="#FFF" 
     android:textSize="20sp" > 
    </EditText> 

这个之后还有一些edittext,但这是它的要点。如果你看到一些愚蠢的东西,让我知道。

+0

你可以给它的外观在您的手机或模拟器截图? –

回答

10

您的背景是在线性布局在ScrollView中。 如果您将滚动视图放在另一个线性布局中,该布局是ScrollView的父级,并且包含背景并将线性布局中的背景从滚动视图的子级移除,则问题将得到解决。

它看起来就像这样:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/app_background" > 
<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:fillViewport="true" > 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:padding="10dp" > 

<EditText 
    android:id="@+id/editText1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:ems="20" 
    android:inputType="textMultiLine" 
    android:lineSpacingExtra="3dp" 
    android:text="THE LONG TEXT YOU'VE TYPED" 
    android:textColor="#FFF" 
    android:textColorLink="#FFF" 
    android:textSize="20sp" > 
</EditText> 
</LinearLayout> 
</ScrollView> 
</LinearLayout> 
1

我觉得滚动视图应填写家长,由于layout_height是大小,视图实际上将在屏幕上,滚动事情的看法

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    //... 
    android:layout_height="fill_parent" 
    //... 
> 

编辑
内发生的儿童观包裹内容 正如dbalaouras所指出的,由于后者已被弃用,所以更好地使用“match_parent”而不是“fill_parent”。结果是一样的,只是因为“填充”令人困惑而改变了名称,如果您设置它不会填充剩余空间,而只是根据其父项设置尺寸

+1

更好地使用“match_parent”来代替。 fill_parent“从API级别8开始被弃用,并被替换为match_parent”(http://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html) – dimi

+0

@lelloman我将scrollview更改为match_parent及其子级包装内容,但它没有改变任何东西。增加的长度似乎来自线性布局,因为当我删除它时,屏幕长度恢复正常。顺便说一句,我在eclipse中看到增加的长度,而不仅仅是在模拟器上。 – Adama

+0

@lelloman这个问题似乎是我有一个重复的背景资源,当它重复它扩展屏幕很好。我只是制作一个较小的平铺背景,以便它不会延伸到目前为止。 不应该有办法让它不能扩展屏幕吗? – Adama