tags:

views:

50

answers:

1

I want to layout a button with Drawable image on the top of it and text below the image. I am very new to this so please use detailed instructions. I have not experimented with drawable images yet so I want to clarify before I continue.

If I want to above the text (ie the text is not on the image) how do I go about doing this? I also want the text to be centered in below and (working without the drawable) there is a gravity command for center-horizontal and bottom. I tried:

android:gravity="bottom, center_horizontal"

This made an error. Appreciate the help and remember I am a beginner to Eclipse and Java.

Thanks in advance. - James

PS Help me build my rep please.

+1  A: 

Hi,

You can use TextView & create a onClickListener to achieve the same easily:

            tv = (TextView) findViewById(R.id.tv);
            tv.setGravity(Gravity.CENTER);

            String title;
            Drawable icon; 

        tv.setText(title);
        tv.setCompoundDrawablesWithIntrinsicBounds(null, icon, null, null);
        tv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

            }
        });
Sameer Segal
I am already have my 6 buttons in a table layout. Can I put the text view in a table layout? Is this code for XML? I'm not sure I need onClickListener. I have plans to to do other stuff when the button is pushed. I just want it to have an image and text that the user in change on with a LongHoldClick (or whatever the command is). Clicking the button will make another action happen. Sorry if there is any confusion.
AF_Aggie
Hope this helps: http://stackoverflow.com/questions/3535958/3536387#3536387
Sameer Segal