Skip to content Skip to sidebar Skip to footer

What Should My Android Layout Look Like?

I recently asked a question about how to add a view on top of a view, after asking that I realized I needed to added a better layout to my app before proceeding further. I was read

Solution 1:

Try this: http://developer.android.com/resources/tutorials/views/hello-linearlayout.html

It has some very useful information which might help you out in regards to layout_weight as Michell Bak mentioned in the comment.

And here's the page for the Hello Views: http://developer.android.com/resources/tutorials/views/index.html

Not to be rude, but it would be much better for you to peruse these and learn the xml on your own. That way you can actually understand it and be better able to re-create it later.

I was quite overwhelmed at first with all the code I didn't understand (including xml files), but with a little practice it becomes very easy - just time consuming.

The main thing I'm confused about is what kind of View to put in the layout. In the examples they use TextView or ImageView, but mine is a custom view

Well, for your "Custom Data View", you would use a LinearLayout with android:layout_width="fill_parent" and android:layout_height="fill_parent" and android:layout_weight="1" and android:background="#BA4AAB" (See http://www.colorpicker.com/)

Then for your Custom Graph View, I would use: android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="4" android:background="#7D4ABA"

Note the layout_weight and background values I put are kind of guesses, you might have to tweak them some to match what you want.

The two linearlayouts that I mentioned would be inside one larger LinearLayout with android:orientation="vertical"

Then for the data in the top, you would use 4 text Views, and in code, you'd use setText(...) on those text views to put your data in.

In the xml for textview1, you would add android:id="@+id/textview1" then in code add TextView textview1 = (TextView)findviewbyId(R.id.textview1); then textview1.setText(myString);

For the graph in the bottom part, you would use 2 views for the base of the graph, and set there android:layout_width and android:layout_height to whatever suits you using dip, dp, or px units.

For the lines that you draw, I believe you would have to use the canvas class with a bitmap and call canvas.drawLine(...) (see http://developer.android.com/reference/android/graphics/Canvas.html)

Post a Comment for "What Should My Android Layout Look Like?"