Reputation: 7
I am novice on Android programming. My task is simple: I want to create a screen with just two objects:
Is it possible so have a working example, or at least a guideline ?
I know how to subclass a view, and to draw int it, using:
MyView d = new MyView(this);
setContentView(d);
But this fills all the screen with MyView and the button is not visible. Some suggestions ?
Upvotes: 1
Views: 284
Reputation: 4119
You go through android Ui for detail understanding.
When you create an android project in eclipse you'll find res/layout/main.xml and this is where your default UI is defined and that is set using setContentView(R.layout.main); in onCreate method.
To put images you can use imageview and textview for Texts in xml. Like that many widgets are there for edit text, Button etc. A simple example including Imageview,textview and Button:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="HELLO ANDROID"
android:layout_gravity="center"
/>
<Button
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="Click Me"
/>
Upvotes: 0
Reputation: 11230
You need to define a layout file and specify relative position of button and the drawable area. Make sure both of them are not specified as fill_parent in layout_width or layout-height.
Set the contentView to this layout file
Upvotes: 1