我的应用程序中有一个网格视图,我可以动态增加其高度。但我的问题是,每次我增加高度时,滚动条都会滚动到页面中心。什么可能导致此问题?这是我下面的代码:
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;
但我的问题是,每次我增加高度时,滚动条都会滚动到页面中心。
当您打开Activity
时,某些控件需要获得焦点。但在.axml
布局中,没有指定的控件来获取焦点,系统会选择第一个需要焦点的合格控件。
在 LinearLayout
中设置 android:focusableInTouchMode="true"
属性时,LinearLayout
将集中在"开始"屏幕上,NestedScrollView
不会滚动到页面中心。