【问题标题】:How to resize View with pull the edge gesture?如何通过拉边缘手势调整视图大小?
【发布时间】:2017-02-15 18:56:42
【问题描述】:

我正在寻找如下图所示的解决方案:

我需要在一个布局中有两个可调整大小的视图。 用户只需要将分隔线移到顶部(ScrollView B 变高)或底部(ScrollView A 变高)。

产生这种行为的最佳解决方案是什么?我知道我可以从 ScrollView 扩展并覆盖 public boolean onTouchEvent(MotionEvent ev)protected void onDraw(Canvas canvas),但可能有更简单的解决方案。我想避免计算移动的数学。感谢您提供任何信息。

【问题讨论】:

标签: android


【解决方案1】:

如果你想快速解决这个问题,我建议你使用Split Pane Layout

用法:

 <com.mobidevelop.spl.widget.SplitPaneLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:spl="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:id="@+id/splitPaneLayout"
        android:layout_height="match_parent"
        spl:splitterSize="12dp"
        spl:orientation="vertical"
        spl:splitterPosition="50%"
        spl:splitterBackground="#781b23">

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:text="" />

        </ScrollView>

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:text=""/>

        </ScrollView>

 </com.mobidevelop.spl.widget.SplitPaneLayout>

我通过为纵向和横向模式创建两个 xml 解决了您的问题。对于纵向模式,我通过添加spl:orientation="vertical" 将面板的方向设置为垂直,对于横向模式,我通过添加spl:orientation="horizontal" 将面板的方向设置为水平。

完成所有这些之后,我得到了如下所示的外观。

【讨论】:

    【解决方案2】:

    将此作为答案。

    您基本上想要来自 Android N 的分屏视图。您可以将代码基于 SystemUI 中的开源实现: http://androidxref.com/7.1.1_r6/xref/frameworks/base/packages/SystemUI/src/com/android/systemui/stackdivider/DividerView.java

    连同这个手柄: http://androidxref.com/7.1.1_r6/xref/frameworks/base/packages/SystemUI/src/com/android/systemui/stackdivider/DividerHandleView.java

    您可以丢弃所有与堆栈有关的代码(这是您历史中不同活动的屏幕截图行)、总线事件以及任何与运行另一个活动有关的代码,例如用于 Vsyncing 之间的代码应用程序 (mSurfaceFlingerOffsetMs)。

    它应该为您提供非常小且易于使用的类。

    【讨论】:

      猜你喜欢
      • 2011-12-07
      • 2012-01-17
      • 1970-01-01
      • 1970-01-01
      • 2020-10-19
      • 1970-01-01
      • 2017-08-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多