android布局和布局参数

时间:2022-11-05 04:34:52

android线性布局:

    myLinearLayout = new LinearLayout(this); 


    myLinearLayout.setOrientation(LinearLayout.VERTICAL);

    myLinearLayout.setBackgroundColor(android.graphics.Color.WHITE);


LinearLayout布局参数:

    LinearLayout.LayoutParams param1 = new LinearLayout.LayoutParams(

         LinearLayout.LayoutParams.FILL_PARENT,

        LinearLayout.LayoutParams.WRAP_CONTENT);


    myTextView = new TextView(this);

    myTextView.setText(R.string.title);
    myTextView.setTextColor(getResources().getColor(R.drawable.blue));

//使用布局参数,添加控件

    myLinearLayout.addView(myTextView, param1);


//如果控件已经添加了

    LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) content.getLayoutParams();
        linearParams.height = (int) (dm.heightPixels*0.89);
        imageview.setLayoutParams(linearParams);