0

我会知道是否有可能创建一个新的Android活动与线性布局,表格布局,相对布局等比较不同的布局...
我的目标是创建一个活动,其中android加载一些对象(例如笔记)并将这些笔记放入活动中,以便让最终用户在平板电脑的屏幕上留下大量贴子。布局Android活动

我想实现的结果与计算机的布局非常相似,在这里你有很多图标,你可以插入,移除和移动这个代表我的笔记的图标。
我希望使用这样的网格http://developer.android.com/guide/tutorials/views/hello-gridview.html,但这种布局可以让我移动我想要的图标?

+0

@如果认为你可以不知道,如果答案是对我有用prolink007。也许如果我不给+1,也许没用。同样,当一个人给我一个无关紧要的答案时,我不会给-1。 – 2012-03-29 08:01:13

回答

1

您需要手动在屏幕上绘制视图,可能使用类似Canvas的东西。这将允许你在你喜欢的地方绘制你的视图。

+0

Mimminito,但我的笔记数量不固定,所以我会有一个程序在屏幕上为每个新笔记画一个新的笔记? – 2012-03-28 15:04:37

+1

这是你必须开发的东西。只需要一个方法,创建一个新的笔记,并将其呈现在屏幕上。您应该了解Android Canvas的工作原理和OpenGL技术。 – Mimminito 2012-03-28 15:33:05

2

事情是这样的:

public class MyActivity extends Activity { 

    private RelativeLayout _mainLayout; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     _mainLayout = (RelativeLayout) findViewById(R.id.canvas); 
     addChild(50, 50, 150, 150, Color.RED); 
     addChild(150, 250, 50, 50, Color.GREEN); 
     addChild(200, 200, 100, 100, Color.BLUE); 
    } 

    public void addChild(int centerX, int centerY, int width, int height, int color) { 
     int X = centerX - width/2; 
     int Y = centerY - height/2; 

     RelativeLayout child = new RelativeLayout(this); 
     child.setBackgroundColor(color); 
     RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(width, height); 
     layoutParams.leftMargin = X; 
     layoutParams.topMargin = Y; 
     layoutParams.bottomMargin = -250; 
     layoutParams.rightMargin = -250; 
     child.setLayoutParams(layoutParams); 
     _mainLayout.addView(child); 
    } 
} 

的main.xml:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 

<RelativeLayout 
       android:id="@+id/canvas" 
       android:orientation="vertical" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:background="@drawable/bg0large" 
     > 
</RelativeLayout>