android - 如何在 2 个布局之间动态移动分隔线/拆分?

标签 android android-layout

我在同一个 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/

相关文章:

android - 在渲染到布局之前获取 TextView 的高度

java - 停止并重新启动已运行的线程

android - 在 Android 的 alertdialog builder 中显示 html 文件

android - 在屏幕android上更改对话框的位置

android - R.layout-land 无法解析为变量

java - 我如何追踪哪个图像是我的应用程序的 killer ?

android - 如何确定移动应用程序中用户的登录状态

java - 如何在单独的 View 中获取 TextView 的 OnClick 事件?

android - 将样式应用于每个 subview

android - 如何保持android :groupIndicator in ExpandableListView?的纵横比