chosenOne Thabs
chosenOne Thabs

Reputation: 1640

Xamarin Gridview Height Skew Scrollview

I have a gridview in my app and i'm able to increase its height dynamically. But my issue is that every time i increase the height, the scrollbar scrolls to the center of the page. What could cause this issue ? Here is my code below :

Axml :

  <android.support.v4.widget.NestedScrollView

      android:layout_width="match_parent"

      android:layout_height="match_parent"
>

       <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

                   android:layout_width="match_parent"

                   android:layout_height="wrap_content"

                   android:orientation="vertical"

                   android:gravity="center"

                   android:background="#e1effa">
               <GridView

                   android:id="@+id/gvPhones"

                   android:layout_width="fill_parent"

                   android:layout_height="wrap_content"

                   android:gravity="center"

                   android:verticalSpacing="5dp"

                   android:drawSelectorOnTop="true"

                   android:stretchMode="columnWidth" />

       </LinearLayout>


 </android.support.v4.widget.NestedScrollView>

Cs :

  _mySimpleItemLoader = new LoadRecords();
  _mySimpleItemLoader.LoadMoreItems();

  gvPhone = FindViewById<GridView>(Resource.Id.gvPhones);
   _gridviewAdapter = new PhonesAdapter(this, _mySimpleItemLoader, this);
   gvPhone.Adapter = _gridviewAdapter;
   gvPhone.LayoutParameters.Height = 777 * gvPhone.Count;

Upvotes: 0

Views: 147

Answers (1)

York Shen
York Shen

Reputation: 9084

But my issue is that every time i increase the height, the scrollbar scrolls to the center of the page.

When you open an Activity, some control needs to take focus. But in your .axml layout there's no designated control to take focus, the system chooses the first eligible control that wants focus.

When you set the android:focusableInTouchMode="true" property in your LinearLayout, your LinearLayout will be focused on start and your NestedScrollView won't scroll to the center of the page.

Upvotes: 1

Related Questions