如何在拖放时自动滚动ScrollView

时间:2015-12-02 06:02:38

标签: android drag-and-drop scrollview autoscroll

stackoverflow中有太多的答案,我尝试了其中一些,但没有得到解决方案。这就是我发布我的代码的原因,请检查并告诉我在哪里放置自动滚动。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/button_text">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:background="?attr/colorPrimary"
    android:elevation="6dp"
    android:minHeight="?attr/actionBarSize"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="30dp"
    android:background="#3D3D3D"
    android:id="@+id/textrelative"
    android:layout_below="@+id/toolbar"
    android:layout_alignParentStart="true">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="#ffffff"
        android:id="@+id/textView1"
        android:layout_centerVertical="true"
        android:layout_alignParentStart="true"
        android:textSize="7pt"
        android:paddingTop="2dp"
        android:paddingBottom="2dp"
        android:paddingLeft="10dp"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Press and hold an item to rearrange"/>

</RelativeLayout>

<ScrollView
    android:id="@+id/mainScroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/textrelative"
    android:layout_above="@+id/bottomLayout">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="4dp"
        android:orientation="vertical">

        <editsetting.LinearLayoutListView
            android:id="@+id/pane1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="50dp"
            android:layout_marginTop="0dp">

            <ListView
                android:id="@+id/listview1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

            </ListView>

        </editsetting.LinearLayoutListView>

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:layout_marginTop="0dp"
            android:layout_below="@+id/pane1"
            android:background="#f1f2f2"
            android:layout_alignParentStart="true">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="#939393"
                android:id="@+id/textView"
                android:layout_centerVertical="true"
                android:layout_alignParentStart="true"
                android:textSize="7pt"
                android:paddingTop="2dp"
                android:paddingBottom="2dp"
                android:paddingLeft="10dp"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="Hidden"/>

        </RelativeLayout>

        <editsetting.LinearLayoutListView
            android:id="@+id/pane2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:minHeight="100dp"
            android:layout_marginTop="0dp">

            <ListView
                android:id="@+id/listview2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

            </ListView>

        </editsetting.LinearLayoutListView>

    </LinearLayout>

</ScrollView>

<LinearLayout
    android:id="@+id/bottomLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:orientation="horizontal"
    android:layout_alignParentEnd="true"
    android:layout_alignParentStart="true">

    <Button
        android:id="@+id/cancelbutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/button_border"
        android:textColor="#000"
        android:text="Cancel" />

    <Button
        android:id="@+id/doneButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@color/button_background"
        android:textColor="@color/button_text"
        android:text="Done"/>

</LinearLayout>

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/coordinatorLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</android.support.design.widget.CoordinatorLayout>

</RelativeLayout>

这是我的xml,我需要做的就是在我的java文件中自动滚动。

with the help of these link i have created drag and drop

现在请帮帮我。

0 个答案:

没有答案
相关问题