我有这个items.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:focusable="true"
android:clickable="true"
android:background="?android:attr/selectableItemBackground"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="60dp"
android:id="@+id/colorPreview" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textAppearance="@android:style/TextAppearance.Large"
android:textColor="@android:color/white"
android:id="@+id/colorName" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
当我单独使用它时,selectableItemBackground在我单击视图时动画.但是当我将它用于RecyclerView中的项目时,对点击的影响不再发生.我怎样才能解决这个问题?
PS:这是RecyclerView上的监听器,如果它是相关的:
public ColorListOnItemTouchListener(Context context, OnItemClickListener clickListener) {
mClickListener = clickListener;
mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onDown(MotionEvent e) {
return true;
}
@Override
public void onLongPress(MotionEvent e) {
if(childView != null && mClickListener != null) {
mClickListener.onItemLongPress(childView, index);
}
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
if(childView != null …Run Code Online (Sandbox Code Playgroud) 我是Android新手,我正在创建Listview弹出菜单.但我有它width和height问题.弹出菜单可以采用更高的高度和宽度.SO中有很多问题,但这些都没有帮助我.
要创建弹出菜单,我尝试了以下方法.
1] 使用弹出菜单和下面的代码:
private void showPopupMenu(View view){
Context wrapper = new ContextThemeWrapper(this, R.style.PopupMenu);
PopupMenu popupMenu = new PopupMenu(wrapper,view);
popupMenu.getMenuInflater().inflate(R.menu.popup_menu,popupMenu.getMenu());
popupMenu.show();
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener(){
@Override
public boolean onMenuItemClick(MenuItem item){
switch (item.getItemId()){
case R.id.install:
Intent intent = new Intent(ViewAllRelationActivity.this,EditRelativeActivity.class);
startActivity(intent);
break;
case R.id.addtowishlist:
break;
}
return false;
}
});
}
Run Code Online (Sandbox Code Playgroud)
它给出了这个输出:
2] 使用ContextMenu,它显示以下输出:
我们可以在ContextMenu中保持宽度和高度但它始终显示在Center中 not each row of our Listview Data …