2016-04-14 7 views

答えて

1

長押しのために使用このコードを

public class HintedImageButton extends ImageButton implements OnLongClickListener 
{ 
    private OnLongClickListener mOnLongClickListener; 

    public HintedImageButton(Context context) 
    { 
     super(context); 

     setOnLongClickListener(this); 
    } 

    public HintedImageButton(Context context, AttributeSet attrs) 
    { 
     super(context, attrs); 

     setOnLongClickListener(this); 
    } 

    @Override public void setOnLongClickListener(OnLongClickListener l) 
    { 
     if (l == this) 
     { 
      super.setOnLongClickListener(l); 
      return; 
     } 

     mOnLongClickListener = l; 
    } 

    @Override public boolean onLongClick(View v) 
    { 
     if (mOnLongClickListener != null) 
     { 
      if (!mOnLongClickListener.onLongClick(v)) 
      { 
       handleLongClick(); 
       return true; 
      } 
     } 
     else 
     { 
      handleLongClick(); 
      return true; 
     } 

     return false; 
    } 

    private void handleLongClick() 
    { 
     String contentDesc = getContentDescription().toString(); 
     if (!TextUtils.isEmpty(contentDesc)) 
     { 
      int[] pos = new int[2]; 
      getLocationInWindow(pos); 

      Toast t = Toast.makeText(getContext(), contentDesc, 1200); 
      t.setGravity(Gravity.TOP | Gravity.LEFT, pos[0] - ((contentDesc.length()/2) * 12), pos[1] - 128); 
      t.show(); 
     } 
    } 
} 

詳細についてまあ、私は画像とリサイクルのビューを使用しています。このhttps://gist.github.com/scruffyfox/3894926

+0

それはダイアログのスタイルで活動するために、私はこれを実装し – HendraWD

2

をご覧ください。

public void publicationQuickView(Post post){ 
    View view = getLayoutInflater().inflate(R.layout.quick_view, null); 

    ImageView postImage = (ImageView) view.findViewById(R.id.ivFeedCenter); 
    ImageView profileImage = (ImageView) view.findViewById(R.id.ivUserProfile); 
    TextView tvUsername = (TextView) view.findViewById(R.id.txtUsername); 
    tvUsername.setText(post.user.name); 

    Picasso.with(this).load(post.picture).priority(Picasso.Priority.HIGH).noPlaceholder().into(postImage); 
    Picasso.with(this).load(post.user.picture).noPlaceholder().into(profileImage); 

    builder = new Dialog(this); 
    builder.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    builder.getWindow().setBackgroundDrawable(
      new ColorDrawable(Color.TRANSPARENT)); 
    builder.setContentView(view); 
    builder.show(); 
} 

私はレイアウトを膨らませるとダイアログに注入:

は、私は、このメソッドを呼び出し長押しリスナーを使用した画像を表示します。

rvUserProfile.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() { 
     @Override 
     public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) { 
      if(e.getAction() == MotionEvent.ACTION_UP) 
       hideQuickView(); 
      return false; 
     } 

     @Override 
     public void onTouchEvent(RecyclerView rv, MotionEvent event) { 
     } 

     @Override 
     public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { 
     }}); 

そして最後に:私は(RecyclerView.OnItemTouchListenerを使用していダイアログを閉じ

)このよう

public void hideQuickView(){ 
    if(builder != null) builder.dismiss(); 
} 
+0

に失敗しています。それは大丈夫です。しかし、ウィンドウが表示されている間にドラッグすると、リストビューがスクロールしていきます。その後、あなたが指を持ち上げると、ウィンドウが自動的に閉じない。 Instagramはこれをどうにかして解決しました。回避策を提案できますか? –

関連する問題