开发者

Positioning text below image

I'm trying to put in RelativeLayout an image and text, and would like the text was down but over the image.

My code:

        RelativeLayout rl;
        //
        rl = new RelativeLayout(mContext);
        rl.setLayoutParams(new GridView.LayoutParams(85, 85));
        rl.setGravity(Gravity.CENTER);
        ImageView imageView = new ImageView(mContext);
        imageView.setId(1);
        TextVi开发者_开发百科ew textView = new TextView(mContext);
        textView.setId(2);
        //              
        imageView.setImageResource(mThumbIds[position]);
        textView.setText(mTextMenu[position]);
        //
        rl.addView(imageView);
        //
        RelativeLayout.LayoutParams mParams = new RelativeLayout.LayoutParams(
                LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
        //                  
        mParams.addRule(RelativeLayout.ALIGN_BOTTOM, imageView.getId());            
        rl.addView(textView, mParams);


Use linear layout. Thats more appropriate for your case.


I managed to solve by changing the layout of the TextView:

        childParams = new RelativeLayout.LayoutParams(65, 25);
        childParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        childParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
        rl.addView(textView, childParams);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜