2 qq 26248529 qq_26248529 于 2016.02.01 16:50 提问

请教Android前辈,动态设置布局里如何设置子布局的位置???

就是平时新闻或者广告的定时滑动,广告底边不是有一条半透明的带和可以跟随滑动的几个圆点,我用LayoutParams写的布局,结果出来效果 圆点全叠在一起了,那半透明的带也在顶部去了,我想知道怎么才能把圆点分开且半透明的带也在底部?谢谢了!

public class FragmentDemo extends Fragment {
private ImageView mImageIds[];
private int index=0;//记录选中的图片位置
private static final int IMAGE_COUNT=3;//小圆点个数
Gallerys_Advertisement gallery;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
//整个Tabs之下的容器
LayoutParams SclayoutParams=new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.MATCH_PARENT);
ScrollView scrollView=new ScrollView(getActivity());
scrollView.setLayoutParams(SclayoutParams);
//界面布局容器一
RelativeLayout R2Layout=new RelativeLayout(getActivity());
LayoutParams R2params=new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
R2Layout.setLayoutParams(R2params);

    //画廊
    LayoutParams galleryParams=new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
    gallery=new Gallerys_Advertisement(getActivity());
    gallery.setFadingEdgeLength(0);//消除图片两边的阴影
    gallery.setSpacing(0);
    gallery.setLayoutParams(galleryParams);
    //界面布局容器二
    RelativeLayout relativeLayout=new RelativeLayout(getActivity());

    //原来Layoutparams设置布局要使用Margins必须要加容器类型在Params语句前如下:RelativeLayout。
    RelativeLayout.LayoutParams RRparams=new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,50);
    //      RRparams.setMargins(0, 0, 0, 0);
    relativeLayout.setBackgroundColor(getResources().getColor(R.drawable.beijingse));//设置自定义背景色
    relativeLayout.setLayoutParams(RRparams);
    relativeLayout.setGravity(Gravity.CENTER);//确定圆点位置居中

    //三张图
    LayoutParams IVparams1=new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
    ImageView imageView1=new ImageView(getActivity());
    imageView1.setImageDrawable(getResources().getDrawable(R.drawable.ic_dot_focused));//重点:添加自定义图片
    imageView1.setLayoutParams(IVparams1);



    LayoutParams IVparams2=new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
    ImageView imageView2=new ImageView(getActivity());
    imageView2.setImageDrawable(getResources().getDrawable(R.drawable.ic_dot_normal));//重点:添加自定义图片
    imageView2.setLayoutParams(IVparams2);



    LayoutParams IVparams3=new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
    ImageView imageView3=new ImageView(getActivity());
    imageView3.setImageDrawable(getResources().getDrawable(R.drawable.ic_dot_normal));//重点:添加自定义图片
    imageView3.setLayoutParams(IVparams3);



    relativeLayout.addView(imageView1);
    relativeLayout.addView(imageView2);
    relativeLayout.addView(imageView3);
    R2Layout.addView(gallery);
    R2Layout.addView(relativeLayout);
    scrollView.addView(R2Layout);

    mImageIds=new ImageView[]{imageView1,imageView2,imageView3};
    mImageIds[0].setImageDrawable(getActivity().getResources().getDrawable(R.drawable.ic_dot_focused));
    ImgAdapter Gadapter=new ImgAdapter(getActivity());
    gallery.setAdapter(Gadapter);

// Timer timer=new Timer();
// timer.schedule(task, 2000,2000);
// gallery.setOnItemSelectedListener(onItemSelectedListener);

    return scrollView;


}

1个回答

qq_26248529
qq_26248529   2016.02.01 17:16
已采纳

图片说明图片说明图片说明我知道如何解决了,不好意思!此问题作废。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!