ScrollView不起作用。

3

我在主页面上有一个列表,但问题是当我扫描了超过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>

有任何建议吗?

3个回答

1
在Android中,不可能在ScrollView中使用ListView。为了实现相同的结果,您可以使用ListView并添加标题和页脚。 addHeaderView() 您可以使用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));
的工作方式完全相同。

嗨,谢谢你的代码,但我有一个疑问,我没有使用ListAdapter,而只是listView,似乎我别无选择,只能使用ListAdapter? - Thet Mon Aye
无论您如何添加项目,标题和页脚部分都很重要。 - flo
谢谢Flo,我认为我最好也展示一下Java代码,因为我越来越困惑了..... - Thet Mon Aye

1

0

你可以使用 RelativeLayout 代替 LinearLayout。

在这种情况下,你应该将按钮放置在布局的底部。之后其他控件应该放置在按钮上方。RelativeLayout具有特殊的xml属性来帮助你做到这一点。然后你就不需要一个ScrollView了。


你的意思是我只使用RelativeLayout而不使用LinearLayout吗? - Thet Mon Aye
我相信我已经尝试过那个了,但它只是显示错误消息并且应用程序崩溃,但我会再试一次。 - Thet Mon Aye
我的意思是,你应该删除“ScrollView”,并将“LinearLayout”替换为“RelativeLayout”。 - Taras Feschuk

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接