2012-07-20 40 views
1

好吧不同的,所以我很快就创建一个包含以下内容的XML文件:Android的开发 - 图形化的布局看起来与实际的XML

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <ScrollView 
     android:id="@+id/scrollView1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

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

      <TextView 
       android:id="@+id/textView1" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:gravity="center" 
       android:text="Text View 1" 
       android:textSize="30dp" /> 

      <ListView 
       android:id="@+id/listView1" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       > 
      </ListView> 

         <TextView 
       android:id="@+id/textView2" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:gravity="center" 
       android:text="Text View 2" 
       android:textSize="30dp" /> 


      <ListView 
       android:id="@+id/listView2" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       > 
      </ListView> 

       <TextView 
       android:id="@+id/textView3" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:gravity="center" 
       android:text="Text View 3" 
       android:textSize="30dp" /> 


      <ListView 
       android:id="@+id/listView3" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       > 
      </ListView> 

     </LinearLayout> 

    </ScrollView> 

</LinearLayout> 

,问题是,是,为什么它看起来这么多不同的,当我点击在“图形布局”选项卡上?我所想象的图形布局看起来基本上是3个标签,这是因为我将所有东西都设置为包装内容,并且因为ListView中没有任何项目,所以我认为它不会是'甚至可以看到)。但无论如何,图形布局显示它是:

Graphical Layout

我不知道如果这是正确与否,如果我运行它,它看起来像我想象的那么看?我基本上希望(1 ScrollView内的所有内容)3个TextView和1个ListView紧跟在每个TextView之后。所以布局将如下所示:

ScrollView 
TextView 
ListView 
TextView 
ListView 
TextView 
ListView 
End of ScrollView 

与上面显示的布局完全相同。有人可以告诉我,在我的XML文件中,所有其他标签上没有显示的错误是什么?

注:当我点击侧面的组件时,似乎有一些事情正在改变。 (当我尝试点击TextView2(尝试搜索蓝色边界框)时,似乎TextView1标签被推下了一点,第二个TextView仍然不可见。如果任何人可以请帮助我实现布局我想,这将不胜感激

回答

1

编辑:。看看这种方法

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" >   

    <ScrollView 
     android:id="@+id/scrollView1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:text="Text View 1" 
      android:textSize="30dp" /> 


    </ScrollView>    

    <ScrollView 
     android:id="@+id/scrollView2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/scrollView1"> 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:text="Text View 2" 
      android:textSize="30dp" /> 


    </ScrollView> 



    <ScrollView 
     android:id="@+id/scrollView3" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/scrollView2" > 

     <TextView 
      android:id="@+id/textView3" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:text="Text View 3" 
      android:textSize="30dp" /> 


    </ScrollView> 

</RelativeLayout> 

至于ListView你不应该把ListView一个ScrollView内这就是为什么大家一个交代。不应该把ListView放在ScrollView之内:Listview inside ScrollView

+0

这就是我想要的,我很欣赏你的答案,但是如何将ScrollView的内部结合到其中?我想在每个TextView下有一个ScrollView。 – 2012-07-20 01:59:45

+0

看看我的编辑,在底部。 – 0gravity 2012-07-20 02:00:29

+0

对不起,从来没有注意到,我明白了。但基本上我对这件事的看法是,如果我没有包含所有内容的ScrollView,如果列表中包含太多的信息,你将无法看到任何其他的东西。例如:如果在第一个ListView中有20个元素(这将填满整个屏幕),我知道里面会有一个ScrollView,但是在完成滚动之后,我的其他TextView和ListView是否可见下降的方式? – 2012-07-20 02:04:41

相关问题