2017-08-08 5 views
0

を返します私はスライドにしたい特定の要素(オーバーレイ)FindByViewIdは、私はつかむ必要がある方法(これは、全体のリストビューアイテムを通過)Iビューを通るI左/スライドをスライドさせるために右</p> <p>を見る上でリッスンタッチリスナーを有するヌル

ここではタッチイベント

public bool OnTouch(View v, MotionEvent e) 
     { 
      switch (e.Action) 
      { 
       case MotionEventActions.Down: 
        { 
         this._downX = e.GetX(); 
         this._downY = e.GetY(); 
        return true; 
       } 
      case MotionEventActions.Up: 
       { 
        this._upX = e.GetX(); 
        this._upY = e.GetY(); 

        float deltaX = this._downX - this._upX; 
        float deltaY = this._downY - this._upY; 

        // swipe horizontal? 
        if (Math.Abs(deltaX) > MIN_DISTANCE) 
        { 
         //left or right 
         if (deltaX < 0) 
         { 
          this.onLeftToRightSwipe(v); 
          return true; 
         } 
         if (deltaX > 0) 
         { 
          this.onRightToLeftSwipe(v); 
          return true; 
         } 
        } 

        return false; 
       } 
     } 
     return false; 
    } 

を上だと、ここsliderViewがNull返すスライド方式だ

public void onRightToLeftSwipe(View v) 
    { 
     View view = v; 

     Animation slideLeft = AnimationUtils.LoadAnimation(this._activity, Resource.Animation.slide_left); 

     View sliderView = v.FindViewById(Resource.Id.list_view_item_parent); //THIS RETURNS NULL 
     sliderView.StartAnimation(slideLeft); 
    } 

これは、vはRelativeLayoutと私はlist_view_item_parent何が起こっている

<?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"> 
    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" 
    android:gravity="right"> 
    <Button 
     android:text="Adjust" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
    <Button 
     android:text="Edit" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
    <Button 
     android:text="Move" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
    </LinearLayout> 
    <LinearLayout 
    android.id="@+id/list_view_item_parent" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#ff000000"> 

任意のアイデアをつかむしようとしていますされて関連するレイアウトの一部ですか?

答えて

0

今のところ私は相対レイアウト内の他のビューが3人の子供を持っているので、1人の子供だけのビューのすべての子供を循環する作業を使用しています...これは汚れていますが、このケースでは機能します。しかし、より良い答えを探しています。

public void OnRightToLeftSwipe(View v) 
    { 
     View view = v; 

     Animation slideLeft = AnimationUtils.LoadAnimation(this._activity, Resource.Animation.slide_left); 

     View sliderView = null; 
     int count = ((RelativeLayout)v).ChildCount; 
     for(int i = 0; i < count; i++) 
     { 
      View v2 = ((RelativeLayout)v).GetChildAt(i); 
      if (((LinearLayout)v2).ChildCount == 1) 
      { 
       sliderView = v2; 
       break; 
      } 
     } 

     //View sliderView = v.FindViewById(Resource.Id.list_view_item_parent); 
     sliderView.StartAnimation(slideLeft); 
    } 
関連する問題