gpt4 book ai didi

android - Android 中 ScrollView 下方的 ListView

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:53:59 25 4
gpt4 key购买 nike

我想在 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>

并且 ListView 没有显示。我也尝试将它放在 RelaviteLayout 中,但仍然没有。我能以某种方式在 ScrollView 下有一个 ListView 吗?

只是想补充一点。我不想分割我的屏幕,这样我有一半是 ScrollView,另一半是 ListView。我希望用户向下滚动显然大于屏幕尺寸的 ScrollView,然后 ListView 应该开始

最佳答案

我建议您将 ScrollView 内容作为 HeaderView 放在 ListView 中,或者您是否明确希望在屏幕上有两个单独的可滚动区域?

将 ScrollView 的内容作为标题(一个单独的可滚动区域)放在列表​​ View 中的示例:

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);

}

Activity 的布局如下所示:

    <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>

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

<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>

关于android - Android 中 ScrollView 下方的 ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18331849/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com