滚动视图不工作
我在我的主要列表中,但问题是,当我扫描超过15条码的条码,然后它没有显示“扫描”按钮,我试图使用滚动视图为但它不工作: 任何帮助吗?滚动视图不工作
<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>
有什么建议吗?
通常在滚动视图内放置一个listview是一个坏主意。它没有按预期工作。看到下面的帖子: https://groups.google.com/forum/?fromgroups#!topic/android-beginners/LRpLgGOy2Pc
在Android中,不可能在ScrollView中使用ListView。为了达到相同的结果,您可以使用ListView并添加页眉和页脚。
可以使用ListActivity。为您的标题创建一个XML布局文件,并把它添加到ListView:(调用setAdapter()
之前将代码放在你的onCreate()
功能)
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));
页脚的工作方式完全相同。
你好,我可以知道如何做到这一点详细吗?谢谢:) – 2012-03-20 01:03:09
嗨,谢谢你的代码,但我有一个奇迹,我没有使用ListAdapter,但只是listView,似乎我别无选择,只能使用ListAdapteR? – 2012-03-20 12:28:26
如何添加项目并不重要,带页眉和页脚的部分很重要。 – flo 2012-03-20 14:17:32
嗨,你可以使用RelativeLayout而不是LinearLayout。
在这种情况下,您应该将按钮放在布局的底部。之后,其他控件应放置在按钮上方。 RelativeLayout有特殊的xml属性来帮助你做到这一点。之后,你不需要一个ScrollView。
嗨你是说我只使用RelativeLayout而不使用LinearLayout? – 2012-03-20 19:34:23
我相信我已经厌倦了一个,但它只是告诉我的错误消息和应用程序粉碎,但我会再试一次 – 2012-03-20 19:35:03
我的意思是,你应该删除'ScrollView',并用'RelativeLayout'替换'LinearLayout' – 2012-03-21 07:27:20
嗨我试过了,但没有设法做到这一点:( – 2012-03-20 01:04:49