开发者

Button Layout with Drawable and Text

开发者 https://www.devze.com 2023-01-13 03:37 出处:网络
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 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.


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

            }
        });
0

精彩评论

暂无评论...
验证码 换一张
取 消