2013-11-15 50 views
0

滚动我有这样的布局:RelativeLayout的具有两个列表视图

<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" 
tools:context=".MainActivity" > 

<TextView 
    android:id="@+id/campomodulo" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="21sp" 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 

<ListView 
    android:id="@+id/listagiocatori" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/campomodulo" > 

    </ListView> 

    <ListView 
    android:id="@+id/panchina" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/listagiocatori" > 

</ListView> 

第一列表视图填充大约一半显示,加入第二正下方的是,这两个列表视图的总高度超过屏幕,所以我有第二个listview的滚动。

我想要一般的滚动,不仅仅是第二个listview。我怎样才能做到这一点?

回答

0

您可以使用独特的ScrollView,然后创建两个不同的线性布局来“实现”您的列表视图。然后您以编程方式添加您的项目是这样的:

LinearLayout layout = (LinearLayout)findViewById(R.id.MyListLayout); 
for (int i=0; i<list.size(); i++) { 
Item item = list.get(i); 
View view = inflater.inflate(R.layout.MyRowLayout, null); 
Textview myTextView = view.findViewById(R.id.MyTextView); 
myTextView.setText(item.getString()); 
list.addView(vi); 

主要的布局应该与此类似:

<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" 
tools:context=".MainActivity" > 

<TextView 
android:id="@+id/campomodulo" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:textSize="21sp" 
android:textAppearance="?android:attr/textAppearanceMedium" /> 

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

<LinearLayout 
    android:id="@+id/listagiocatori" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 
</LinearLayout> 

<LinearLayout 
    android:id="@+id/panchina" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/listagiocatori" > 
</LinearLayout> 
</ScrollView> 

然后你只需要为它添加到设置一个简单的布局,每排适当的布局。它可以是简单的TextView或更复杂的布局

相关问题