主布局
<LinearLayout
android:layout_width="0dp"
android:layout_weight="4"
android:layout_height="match_parent">
<View
android:paddingBottom="5dp"
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="match_parent"/>
<ImageView
android:id="@+id/d_image"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="40dp"
android:src="@drawable/jiahao"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_gravity="center_vertical" />
</LinearLayout>
代码
hotAdapter.setOnItemClickListener(new HotAdapter.OnItemClickListener() {
@Override
//点击事件 public void onItemClick(View view, int position) {
//Toast.makeText(getActivity(),"12"+"--"+position,Toast.LENGTH_SHORT).show();
image = view.findViewById(R.id.d_image);
image.setImageResource(R.drawable.breduce);
//弹框
showPopupWindow(view);
}
private void showPopupWindow(final View vvv) {
View contentView = LayoutInflater.from(getActivity()).inflate(R.layout.photo_popup_layout, null);
mPopWindow = new PopupWindow(contentView,
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
mPopWindow.setContentView(contentView);
mPopWindow.setBackgroundDrawable(new BitmapDrawable());
mPopWindow.setOutsideTouchable(true);
mPopWindow.setAnimationStyle(R.style.AnimationPreview);
ColorDrawable dw = new ColorDrawable(0000000000);
mPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
ImageView image = vvv.findViewById(R.id.d_image);
image.setImageResource(R.drawable.badd);
}
});
contentView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
int mShowMorePopupWindowWidth = -contentView.getMeasuredWidth();
int mShowMorePopupWindowHeight = -contentView.getMeasuredHeight();
mPopWindow.showAsDropDown(vvv,mShowMorePopupWindowWidth, mShowMorePopupWindowHeight);
}
});
布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:padding="6dp"
android:orientation="horizontal"
android:layout_height="match_parent">
<ImageView
android:id="@+id/image_01"
android:padding="4dp"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:src="@drawable/tmess"
android:background="@drawable/blue_cirl"
android:layout_width="30dp"
android:layout_height="30dp" />
<ImageView
android:layout_gravity="center"
android:padding="4dp"
android:layout_marginLeft="10dp"
android:background="@drawable/blue_cirl"
android:src="@drawable/tshar"
android:layout_width="30dp"
android:layout_height="30dp" />
<ImageView
android:padding="4dp"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:background="@drawable/blue_cirl"
android:src="@drawable/thart"
android:layout_width="30dp"
android:layout_height="30dp" />
</LinearLayout>