简体   繁体   中英

Android Button and drawable area

I am novice on Android programming. My task is simple: I want to create a screen with just two objects:

  • an action Button;
  • a drawable area in wich to draw images, text, circles, and so on.

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 ?

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

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"
 />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM