views:

3395

answers:

1

Hi,

I would like to create a button with circular or rectangular background, text and an image below or above the text.

Here is the CustomButton Layout where I added the objects (background and text - ImageView is missing):

<FrameLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_height="wrap_content"
 android:orientation="horizontal" android:layout_width="wrap_content" android:layout_gravity="center_vertical|center_horizontal">

I would like to create a CustomButton object with methods setText() and setImage() which would change the button text and image and place multiple CustomButtons into main layout.

Does anyone know how to create a custom layout, place it into another layout(main) and modify its elements from the activity which is bound to main layout?

I would really appreciate your help.

Thanks!

+3  A: 

If you want programmatic access, you should subclass View and do your work there in java. You can still do the layout in xml, but have the image and text methods that you want. You will then be able to use this in another layout to place your CustomButtons.

AdamC
When you extend the view Class, you'll need to override onDraw and the key handling functions.
haseman