Android scrollview不工作
我的main中有一个列表,但问题是,当我扫描超过15个条形码时,它没有显示“扫描”按钮,我尝试使用滚动视图,但它不起作用: 有什么帮助吗Android scrollview不工作,android,list,Android,List,我的main中有一个列表,但问题是,当我扫描超过15个条形码时,它没有显示“扫描”按钮,我尝试使用滚动视图,但它不起作用: 有什么帮助吗 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:fillViewport="true">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="no notes"
/>
<Button
android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="scan"/>
</LinearLayout>
</ScrollView>
有什么建议吗?通常,在scrollview中放置listview是个坏主意。它没有按预期工作。见以下帖子:
在Android中,无法在滚动视图中使用ListView。为了获得相同的结果,可以使用ListView并添加页眉和页脚 您可以使用ListActivity。为标题创建一个xml布局文件并将其添加到ListView:(在调用
setAdapter()
之前,将代码放入onCreate()
函数中)
页脚的工作方式完全相同。您好,您可以使用而不是线性布局
在这种情况下,您应该将按钮放在布局的底部。之后,其他控件应置于按钮上方。RelativeLayout具有特殊的xml属性来帮助您实现这一点。之后,您就不需要滚动视图了。您好,谢谢您的代码,但我有一个疑问,我没有使用ListAdapter,只是使用listView,似乎我别无选择,只能使用ListAdapter?无论您如何添加项目,带有页眉和页脚的部分都很重要。谢谢flo,我想我最好也展示一下Java代码,因为我越来越困惑了……您好,您的意思是我只使用RelativeLayout而不使用LinearLayout吗?我相信我已经厌倦了它,但它只是向我展示了错误消息和应用程序崩溃,但我会再次尝试。我的意思是,您应该删除
ScrollView
,并将LinearLayout
替换为RelativeLayout
LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
getListView().addHeaderView(inflater.inflate(R.layout.header, null));
getListView().addFooterView(inflater.inflate(R.layout.footer, null));