scrollview无法正常工作

时间:2012-03-19 18:55:19

标签: android list

我的主要列表中有一个列表,但问题是当我扫描条形码超过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 个答案:

答案 0 :(得分:1)

通常,将listview放在scrollview中是个坏主意。它没有按预期工作。请看以下帖子: https://groups.google.com/forum/?fromgroups#!topic/android-beginners/LRpLgGOy2Pc

答案 1 :(得分:1)

在Android中,无法在ScrollView中使用ListView。为了获得相同的结果,您可以使用ListView并添加页眉和页脚。

addHeaderView()

您可以使用ListActivity。为标题创建一个xml布局文件并将其添加到ListView :(在调用onCreate()之前将代码放入setAdapter()函数中)

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

页脚的工作原理完全相同。

答案 2 :(得分:0)

嗨,您可以使用RelativeLayout代替LinearLayout。

在这种情况下,您应该将按钮放在布局的底部。之后,其他控件应放在按钮上方。 RelativeLayout具有特殊的xml属性来帮助您完成此操作。之后,您不需要ScrollView。

相关问题