我正在寻找解决方案,如下图所示:
我需要在一个布局中拥有两个可调整大小的视图。 用户只需要将分隔线移到顶部(ScrolView B更高)或底部(ScrolView A更高)。
什么是最佳解决方案,它会产生这种行为?我知道我可以从ScrollView扩展并覆盖public boolean onTouchEvent(MotionEvent ev)
和protected void onDraw(Canvas canvas)
,但可能有更简单的解决方案。我想避免计算移动的数学。感谢您提供任何信息。
答案 0 :(得分:4)
如果您想快速解决此问题,建议您使用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>
我通过为纵向和横向模式创建两个xmls来解决您的问题。对于纵向模式,我通过添加spl:orientation="vertical"
将面板的方向设置为垂直,对于景观模式,我通过添加spl:orientation="horizontal"
将面板的方向设置为水平。
答案 1 :(得分:2)
将此作为答案。
您基本上需要Android N的分屏视图。您可以将您的代码基于SystemUI中的开源实现: http://androidxref.com/7.1.1_r6/xref/frameworks/base/packages/SystemUI/src/com/android/systemui/stackdivider/DividerView.java
您可以丢弃与堆栈有关的所有代码(这是历史记录中不同活动的屏幕截图行),buss事件以及与运行其他活动有关的任何内容,例如之间的Vsyncing代码apps(mSurfaceFlingerOffsetMs)。
它应该为您提供非常小且易于使用的课程。