在Android下面的scrollview下面的ListView

ale*_*ash 4 android android-layout

我试图在android ListView下面放一个ScrollView.我试图把他们内部的LineaLayout这样

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/frameLayout"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical" >
  <ScrollView 
      android:id="@+id/marketDetailScrollView"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" >
   ...
  </ScrollView>
  <ListView  android:id="@android:id/list" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent"
    android:background="#FFF"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

而且ListView没有显示出来.我也试过把它放在一个RelaviteLayout仍然没有.我能以某种方式拥有ListView一个ScrollView吗?

只是添加一些东西.我不想分割我的屏幕,以便我有一半与ScrollView另一半有一个ListView.我希望用户向下滚动ScrollView显然大于屏幕尺寸然后ListView应该开始

soc*_*qwe 10

我建议你把ScrollView内容作为HeaderView放在ListView中,或者你明确想要在屏幕上有两个独立的可滚动区域?

将滚动视图的内容作为标题放入列表视图的示例(单个可滚动区域):

public void onCreate(Bundle s){
    setContentView(R.id.yourLayout);

    ListView listView = (ListView) findViewById(R.id.listView);

    // Set the adapter before the header, because older 
    // Android version may have problems if not

    listView.setAdapter(new YourAdapter());

    // Add the header
    View header = inflater.inflate(
            R.layout.you_layout_that_was_in_scrollview_before, null, false); 

    listView.addHeaderView(header);

}
Run Code Online (Sandbox Code Playgroud)

活动的布局如下:

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

    <ListView  android:id="@+id/listView" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent"
    android:background="#FFF"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

如果您想要两个可滚动区域,则应使用布局权重:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView 
  android:id="@+id/marketDetailScrollView"
  android:layout_width="match_parent"
  android:layout_height="0dp"
  android:layout_weight="1" >
  <!-- ScrollViewContent -->
</ScrollView>
<ListView  android:id="@android:id/list" 
android:layout_height="0dp" 
android:layout_width="match_parent"
android:background="#FFF"
android:layout_weight="1"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)