【问题标题】:scrollview is not working滚动视图不起作用
【发布时间】:2012-03-19 18:55:18
【问题描述】:

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

有什么建议吗?

【问题讨论】:

    标签: android list


    【解决方案1】:

    通常在滚动视图中放置一个列表视图是个坏主意。它没有按预期工作。请参阅以下帖子: https://groups.google.com/forum/?fromgroups#!topic/android-beginners/LRpLgGOy2Pc

    【讨论】:

      【解决方案2】:

      在 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?
      • 如何添加项目并不重要,带有页眉和页脚的部分很重要。
      • 谢谢弗洛,我想我最好也展示一下Java代码,因为我越来越困惑.....
      【解决方案3】:

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

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

      【讨论】:

      • 您好,您的意思是我只使用RelativeLayout 没有LinearLayout?
      • 我相信我已经厌倦了那个,但它只是向我显示错误消息和应用程序迷恋,但我会再试一次
      • 我的意思是,你应该删除ScrollView,并将LinearLayout替换为RelativeLayout
      猜你喜欢
      • 2017-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多