当前位置:编程学习 > wap >>

布局奇怪的效果?!各位能帮忙看看吗?

布局奇怪的效果?!

效果
这是奇怪的图片   
下面是代码
RelativeLayout mvLine = new RelativeLayout(this.getBaseContext());
                                mvLine.setClickable(true);
                                mvLine.setOnClickListener(detailListener);
                                mvLine.setBackgroundDrawable(this.getBaseContext()
                                                .getResources().getDrawable(R.drawable.list_bg));
                                //mvLine.setOrientation(android.widget.LinearLayout.HORIZONTAL);

                                ImageView img = new ImageView(this.getBaseContext());
                                img.setImageDrawable(this.getBaseContext().getResources()
                                                .getDrawable(R.drawable.loading_img));
                                img.setPadding(21, 3, 0, 4);

                                ImageLoader.getInstance().loadImage(
                                                hotmvs.item(i).getAttributes().getNamedItem("subimg")
                                                                .getNodeValue(), img, R.drawable.load_err_img);

                                mvLine.addView(img, ViewGroup.MarginLayoutParams.WRAP_CONTENT,
                                                ViewGroup.MarginLayoutParams.WRAP_CONTENT);

                                LinearLayout ll = new LinearLayout(this.getBaseContext());
                                ll.setOrientation(ll.VERTICAL);

                                // name
                                TextView text = new TextView(this.getBaseContext());
                                text.setText("名称:"
                                                + hotmvs.item(i).getAttributes()
                                                                .getNamedItem("subname").getNodeValue());
                                // 前两位是透明度
                                text.setTextColor(0xff000000);
                                text.setTextSize(16);
                                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                                                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

                                lp.topMargin = 17;
                                lp.leftMargin = 12;
                                ll.addView(text, lp);

                                TextView text2 = new TextView(this.getBaseContext());
                                text2.setText("看点:"
                                                + hotmvs.item(i).getAttributes()
                                                                .getNamedItem("subname").getNodeValue());

                                LinearLayout.LayoutParams lp2 = new LinearLayout.LayoutParams(
                                                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                                lp2.topMargin = 2;
                                lp2.leftMargin = 12;
                                ll.addView(text2, lp2);
                                
                                
                
                                mvLine.addView(ll, ViewGroup.MarginLayoutParams.FILL_PARENT,
                                                ViewGroup.MarginLayoutParams.FILL_PARENT);

                                EditText et = new EditText(this.getBaseContext());
                                et.setText(hotmvs.item(i).getAttributes().getNamedItem(
                                                "contenturl").getNodeValue());
                                et.setVisibility(EditText.GONE);
                                mvLine.addView(et, ViewGroup.MarginLayoutParams.WRAP_CONTENT,
                                                ViewGroup.MarginLayoutParams.WRAP_CONTENT);

                                ImageButton ib = new ImageButton(this.getBaseContext());
                                ib.setBackgroundDrawable(this.getResources().getDrawable(
                                                R.drawable.arrow)); --------------------编程问答-------------------- 你的代码就是这个效果,最外层是一个相对布局,先增加一个ImageView, 有增加了一个线性布局,线性布局没有设置为在ImageView的右侧,默认还是从(0,0)开始。就是楼主现在的情形了。
后买的EditText设置为gone了,当然就不显示。 --------------------编程问答--------------------
// 1.增加一个id
private static final int ID_IMG = 1;

// 2.设置image的id
img.setId(ID_IMG);

// 3.设置线性布局的layout
RelativeLayout.LayoutParams lp3 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);  
lp3.addRule(RelativeLayout.ALIGN_TOP, ID_IMG);  
lp3.addRule(RelativeLayout.RIGHT_OF , ID_IMG);  
mvLine.addView(ll, lp3);
--------------------编程问答-------------------- 相对布局,,组件与组件的位置,组件与屏幕的位置,要清楚如何放置。
补充:移动开发 ,  Android
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,