Scrollview not working

I have a list in my main, but the problem is that when I scan more than 15 barcodes, then it didn’t show the "scan" button anymore, and I tried to use scrolling for that, but it doesn’t work : Any help?

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

      

Any suggestions?

+3


source to share


3 answers


It is generally a bad idea to put a listview inside a scrollview. It doesn't work as expected. See the following post: https://groups.google.com/forum/?fromgroups#!topic/android-beginners/LRpLgGOy2Pc



+1


source


On Android, it is not possible to use ListView in ScrollView. To achieve the same result, you can use a ListView and add a header and footer.

addHeaderView ()

You can use ListActivity. Create one xml layout file for your header and add it to ListView: (put code in your onCreate()

function before calling 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));

      

The footer works the same way.

+1


source


Hi you can use RelativeLayout instead of LinearLayout.

In this case, you should place your button at the bottom of the layout. After that, other controls should be installed above the button. RelativeLayout has special xml attributes to help you do this. After that, you don't need a ScrollView.

0


source







All Articles