如何在Android中创建曲线布局?

时间:2011-07-26 07:57:58

标签: android layout curve

我想创建一个像Sen想要的曲线布局 How to create this layout?

这里在泡泡的地方我需要按钮,这里想要像画廊一样移动布局?

建议我。 感谢

2 个答案:

答案 0 :(得分:1)

使用圆圈中的按钮查看问题布局的this answer。它提供了一种在布局中绘制XY坐标的方法。

编辑2011年7月28日:带有圆圈按钮的second answer布局不包含XML。 @Shubh在下面的评论中提出这个要求,所以我把它放在一起:

<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
    <FrameLayout 
        android:layout_width="130dp"
        android:layout_height="85dp"
        android:background="#FFCC0000">
        <Button 
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_gravity="right|bottom"
        />
    </FrameLayout>  
    <FrameLayout 
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="#FFCCCC00">
        <Button 
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_gravity="right|bottom"
        />
    </FrameLayout>  
    <FrameLayout 
        android:layout_width="85dp"
        android:layout_height="130dp">
        <Button 
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_gravity="right|bottom"
        />
    </FrameLayout>  
</RelativeLayout>

enter image description here

答案 1 :(得分:1)

好的,为了它的价值,我的方法是创建一个自定义布局,可能扩展AbsoluteLayout。您必须查询屏幕尺寸,然后您可以在布局中创建最适合屏幕尺寸的Path或EllipticCurve。接下来,您可以确定要放置图形或按钮的曲线(或曲线偏移)的位置。您还必须通过扩展SimpleOnGesturreListener来创建自定义手势检测器,以便fling操作执行您希望它执行的操作,例如在曲线上的一个或多个或所有对象上进行动画制作。 这显然只是一个起点,但它应该让你开始,一旦你尝试运行它,你会看到需要调整的问题或行为。 祝你好运。

修改:您可以通过传递形状来使其更通用曲线,圆等,然后让它沿着形状的路径布局你的按钮。