setMargins到相对布局不在Grid布局中工作

时间:2015-11-21 07:39:03

标签: android

 GridLayout glSameLoactions;
@OnClick(R.id.tvAddLocation)
void addLocationOnClickListener(){
    if(i==0) {
        glSameLoactions = new GridLayout(this);
        glSameLoactions.setColumnCount(3);
        glSameLoactions.setBackgroundResource(R.drawable.shape_rounded_corner_blurfilled);
        glSameLoactions.setPadding(16,16,16,16);
    }
    RelativeLayout rlLocation = new RelativeLayout(this);
    rlLocation.setPadding(16, 16, 16, 16);
    LinearLayout.LayoutParams relativeParams = new LinearLayout.LayoutParams(300,200);
    relativeParams.setMargins(16, 16, 16, 16);//<<<<----- NOT WORKING
    rlLocation.setLayoutParams(relativeParams);
    rlLocation.requestLayout();
    rlLocation.setBackgroundResource(R.drawable.shape_rounded_corner_blurfilled);

    TextView tvLocationName = new TextView(this);
    tvLocationName.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    tvLocationName.setId(R.id.tvLocationName);
    tvLocationName.setText("amritsar,PB");
    tvLocationName.setTextColor(getResources().getColor(R.color.white));
    tvLocationName.setTextSize(14f);

    ImageView ivRadiobtn = new ImageView(this);
    tvLocationName.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    ivRadiobtn.setImageResource(R.drawable.ic_circle_empty);
    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    rlLocation.addView(tvLocationName);
    rlLocation.addView(ivRadiobtn,lp);
    glSameLoactions.addView(rlLocation);
if (i==0) {
llLocations.addView(glSameLoactions);
llLocations.setVisibility(View.VISIBLE);
}
    i++;

}

我正在以编程方式进行布局,在单击按钮时,会在网格布局中添加新的相对布局。我的所有代码都运行正常,但问题是我无法将边距设置为网格布局内的相对布局。请帮忙!!

由于

1 个答案:

答案 0 :(得分:0)

您应该使用printf代替#pragma omp parallel num_threads(4) { #pragma omp for reduction(+:mean) for (int i=0; i<aSize; i++) { mean = mean + mean_array[i]; } printf("hello %d\n", omp_get_thread_num()); }

试试这个:

RelativeLayout.LayoutParams