我在同一个 xml 文件中有两个布局(顶部布局和底部底部布局)。我希望用户能够捕获将它们分开的边缘,并能够相应地向上或向下移动布局大小。有点像滑动门,但它从中间开始,可以从顶部或底部移动到释放触摸的位置 你说我怎么能做到这一点?我可以在布局边缘实现触摸监听器还是有更好的方法? 谢谢
最佳答案
我这样做的方法是在两个布局之间有一个 View 。布局将有一个例子:
<LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="0.5"/>
<View android:id="@+id/layout_draggable"
android:layout_height="10dip"
android:layout_width="fill_parent" />
<LinearLayout android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="0.5"/>
</LinearLayout>
然后您将在中间 View 上有一个触摸监听器,这将改变两个布局的权重。 float 必须加起来为 1,这样做会使可拖动的 View 也移动。
关于android - 如何在 2 个布局之间动态移动分隔线/拆分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9578856/