我有一个显示图像列表的gridview,我为这个gridview实现了选择模式监听器。问题是,当我按下长按以选择一组图像时,它们不会突出显示..
item_photo.xml
<?xml version="1.0" encoding="utf-8"?>
<ImageView
android:id="@+id/photo"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:contentDescription="@string/media_thumbnail"/>
fragment_photos.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Empty View -->
<RelativeLayout
android:id="@+id/empty_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
<ImageView
android:id="@+id/download_arrow"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_centerInParent="true"
android:contentDescription="@string/downloads"
android:src="@drawable/ic_photo"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/download_arrow"
android:layout_centerInParent="true"
android:layout_marginLeft="32dp"
android:layout_marginRight="32dp"
android:gravity="center"
android:text="@string/no_media"/>
</RelativeLayout>
<!-- Photos List -->
<GridView
android:id="@+id/list"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="3"
android:paddingBottom="5dp"
android:choiceMode="multipleChoiceModal"
android:paddingTop="5dp"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp"
android:visibility="gone"/>
</RelativeLayout>
PhotosFragment.java
public class PhotosFragment extends Fragment
{
@Bind (R.id.list)
GridView mGridView;
private MediaGridAdapter mAdapter;
private ArrayList<File> mFiles;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.fragment_media, container, false);
ButterKnife.bind(this, view);
mGridView.setMultiChoiceModeListener(new MultiChoiceModeListener());
// set adapter and fetch files code ....
return view;
}
}
答案 0 :(得分:0)
没有神奇的高光效果,你必须自己实现它,例如设置一个半透明灰色的前景drawable。