Question

I would know if there is the possibility to create a new Android Activity with a different layout comparing to linear layout, table layout, relative layout ect...
My goal is to create an activity where the android load some object (for example notes) and place this notes into the activity in order to give the illusion at the final user to have a lot of post-it on the screen of the tablet.

The result that i would to achieve is very similar to the layout of computer, where you have a lot of icons and you can insert, remove and move this icon that represent my notes.
I thougth to use a grid like this http://developer.android.com/guide/tutorials/views/hello-gridview.html, but with this kind of layout can i move where i want my icons??

Was it helpful?

Solution

You would need to draw your views manually to the screen, probably using something like a Canvas. This will allow you to draw yours views where you like.

OTHER TIPS

Something like this:

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>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top