0
我有一個自定義適配器Gridview。一切工作正常,但是當我選擇一個GridView的子項並向下滾動時,選擇器顏色被拖拽下來,就像溢出一樣。我嘗試使用自定義選擇器,但它沒有幫助。自定義GridView選擇器顏色溢出或移動或正在被拖動時,我滾動
GridView控件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/popup_layout"
android:layout_gravity="center"
android:weightSum="1"
android:background="#ffffff">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/llayout1"
android:background="@drawable/layout_design">
<TextView
android:text="Name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView6"
android:layout_weight="7"
android:textSize="16sp"
android:paddingLeft="10dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:background="@drawable/edit_style"
android:id="@+id/prototypeName"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/llayout2"
android:layout_below="@+id/llayout1"
android:background="@drawable/layout_design">
<TextView
android:text="Orientation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView7"
android:layout_weight="7"
android:textSize="16sp"
android:paddingLeft="10dp" />
<Spinner
android:id="@+id/spinner"
android:spinnerMode="dialog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"/>
</LinearLayout>
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
android:layout_below="@id/llayout2"
android:numColumns="2"
android:id="@+id/createGrid"
android:listSelector="@color/colorPrimary"
android:choiceMode="singleChoice"/>
截圖:
任何幫助表示讚賞!謝謝。
嘿!我如何獲得適配器內選定的項目?我在我的活動中有一個onItemClickListener(),我嘗試從那裏設置背景,令我驚訝的是沒有顏色拖動。但是現在,如果我選擇第一個孩子並向下滾動,則會看到一個孩子被選中,並且我向前滾動,之前選擇的項目已更改。然後我在onItemClickListener中添加了一個for循環來將所有其他視圖設置爲透明,但是當我滾動時仍然看到一個選擇。感謝您的答覆! –
發生這種情況是因爲GridView項目正在重複使用。你應該改變getView(..)方法在你的適配器中的背景顏色取決於位置參數。 還有一個建議:嘗試使用RecyclerView。 GridView和ListView已過時。 – MonStar