2015-05-28 54 views
0

我正在使用ScrollView,但它不起作用。它没有回应。我想知道是否有人可以在我的XML文件中找到可疑的东西。ScrollView未响应LinearLayout

我确实有其他的xml文件使用相同的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="fill_parent"> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="alias" 
      android:id="@+id/alias" 
      android:layout_marginTop="15dp" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="date_of_post" 
      android:id="@+id/date_of_post" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:text="comment" 
      android:id="@+id/comment" 
      android:layout_marginBottom="15dp" /> 

    </LinearLayout> 

</ScrollView> 
+0

如果你想要它滚动的LinearLayout需要wrap_parent。如果它填满屏幕,它将开始滚动 – Xjasz

+0

我没有看到代码的任何问题,它应该正常工作。您是否在其他地方将此视图充气或将您用作活动的内容视图? –

+0

DDMS视图层次转储对于这样的布局问题是无价的。我建议在调试器中转储视图层次结构。 –

回答

0

试试这个

<?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="fill_parent"> 

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

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:text="alias" 
     android:id="@+id/alias" 
     android:layout_marginTop="15dp" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:text="date_of_post" 
     android:layout_below="@+id/alias" 
     android:id="@+id/date_of_post" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="comment" 
     android:id="@+id/comment" 
     android:layout_below="@+id/date_of_post" 
     android:layout_marginBottom="15dp" /> 

</RelativeLayout> 

</ScrollView> 
+0

仍然无法正常工作... – largow007

+0

然后,您只是没有足够的文字来填充视图。它不会滚动,除非它完整 – Xjasz

+0

我刚刚记得你不想让LinearLayout成为滚动视图的子节点。检查我的编辑 – Xjasz

0

我没有看到什么错在你的XML。我的建议是你应该看看显示器,你的文字浏览是否在屏幕上?因为如果它的屏幕,不会有任何滚动。希望它有帮助^^