Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android中具有多布局的拖放自动滚动_Android_Drag And Drop_Android Scrollview - Fatal编程技术网

android中具有多布局的拖放自动滚动

android中具有多布局的拖放自动滚动,android,drag-and-drop,android-scrollview,Android,Drag And Drop,Android Scrollview,“当我拖放具有多个布局的图像时,自动滚动无法正常工作” 我到处找,但找不到解决办法。 我从这个链接得到了一个解决方案: @thehayro谢谢你给我举了这么好的例子 但它只适用于一种布局,自动滚动也适用。但我在一个线性布局中有4-5个以上的子布局,该布局在滚动视图中,我的布局文件如下所示: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match

“当我拖放具有多个布局的图像时,自动滚动无法正常工作”

我到处找,但找不到解决办法。 我从这个链接得到了一个解决方案:

@thehayro谢谢你给我举了这么好的例子

但它只适用于一种布局,自动滚动也适用。但我在一个线性布局中有4-5个以上的子布局,该布局在滚动视图中,我的布局文件如下所示:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.example.dragvdropdemo.MyScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/scroll_view">
<LinearLayout 
 android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/lldrag">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="200dip" 
    android:id="@+id/ll1"
    android:layout_marginTop="10dip"
     android:background="@android:color/darker_gray">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/dr_logo" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />

    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/fb" />

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="200dip" 
    android:id="@+id/ll2"
    android:layout_marginTop="10dip"
    android:background="@android:color/darker_gray">


    <ImageView
        android:id="@+id/ImageView01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/twitter" />

    <ImageView
        android:id="@+id/ImageView02"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />

    <ImageView
        android:id="@+id/ImageView03"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="200dip" 
    android:id="@+id/ll3"
    android:layout_marginTop="10dip"
     android:background="@android:color/darker_gray">


    <ImageView
        android:id="@+id/ImageView1_l3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/twitter" />

    <ImageView
        android:id="@+id/ImageView2_l3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />

    <ImageView
        android:id="@+id/ImageView3_l3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="200dip" 
    android:id="@+id/ll4"
    android:layout_marginTop="10dip"
     android:background="@android:color/darker_gray">


    <ImageView
        android:id="@+id/ImageView1_l4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/twitter" />

    <ImageView
        android:id="@+id/ImageView2_l4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />

    <ImageView
        android:id="@+id/ImageView3_l4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
 </com.example.dragvdropdemo.MyScrollView>
我是android初学者,所以不太了解它,请告诉我如何解决它。 对不起,我的英语和语法都不好。
感谢进步

我自己解决了这个问题。以下是解决方案:

  DragEvent.ACTION_DRAG_LOCATION:
  //no action necessary
  int y = Math.round(v.getY())+Math.round(event.getY());
      int translatedY = y - mScrollDistance;
      Log.i("translated",""+translatedY+" "+ mScrollDistance+" "+y);
      int threshold =50 ;
      // make a scrolling up due the y has passed the threshold
      if (translatedY < 200) {
         // make a scroll up by 30 px
         myScrollView.smoothScrollBy(0, -15);
      }
      // make a autoscrolling down due y has passed the 500 px border
      if (translatedY + threshold > 500) {
         // make a scroll down by 30 px
         myScrollView.smoothScrollBy(0, 15);
      }
     
    break;
DragEvent.ACTION\u拖动位置:
//无需采取任何行动
int y=Math.round(v.getY())+Math.round(event.getY());
int translatedY=y-滚动距离;
Log.i(“翻译的”,“翻译的+y+”+mScrollDistance+“+y”);
int阈值=50;
//由于y已超过阈值,请向上滚动
如果(平移Y<200){
//向上滚动30像素
myScrollView.smoothScrollBy(0,-15);
}
//进行自动向下滚动,因为y已通过500像素边界
如果(平移Y+阈值>500){
//向下滚动30像素
myScrollView.smoothScrollBy(0,15);
}
打破

但自动向下滚动不起作用
public class MyScrollView  extends ScrollView {

public OnScrollViewListener mListener;

public MyScrollView(Context context, AttributeSet attrs) {
    super(context, attrs);
    // TODO Auto-generated constructor stub
}

@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
    // TODO Auto-generated method stub
    super.onScrollChanged(l, t, oldl, oldt);
    if (mListener != null) {
         mListener.onScrollChanged1(mListener);
     }
}

public void setOnScrollViewListener(OnScrollViewListener listener) {
    mListener = listener;
}
public static interface OnScrollViewListener {
       public void onScrollChanged1(OnScrollViewListener listener);
    }
}
  DragEvent.ACTION_DRAG_LOCATION:
  //no action necessary
  int y = Math.round(v.getY())+Math.round(event.getY());
      int translatedY = y - mScrollDistance;
      Log.i("translated",""+translatedY+" "+ mScrollDistance+" "+y);
      int threshold =50 ;
      // make a scrolling up due the y has passed the threshold
      if (translatedY < 200) {
         // make a scroll up by 30 px
         myScrollView.smoothScrollBy(0, -15);
      }
      // make a autoscrolling down due y has passed the 500 px border
      if (translatedY + threshold > 500) {
         // make a scroll down by 30 px
         myScrollView.smoothScrollBy(0, 15);
      }
     
    break;