简体   繁体   English

如何设置LinearLayout LayoutParams以显示所有高度

[英]How to set LinearLayout LayoutParams to show all height

Based in this question How to set RelativeLayout layout params in code not in xml I've made this code: 基于此问题, 如何用不在xml中的代码设置RelativeLayout布局参数,我编写了以下代码:

    LinearLayout oLl = new LinearLayout(getContext());

    TextView oNum = new TextView(getContext());
    oNum.setText(String.valueOf(nPos + 1) + ". ");
    oNum.setTypeface(null, Typeface.BOLD);
    oNum.setTextColor(Color.RED);
    oNum.setTextSize(18);
    oNum.setPadding(Dp_to_Px(10),Dp_to_Px(15),0,0);

    TextView oText = new TextView(getContext());
    oText.setText(oPreg.getcPregunta());
    oText.setTypeface(null, Typeface.BOLD);
    oText.setTextColor(Color.BLACK);
    oText.setTextSize(18);

    LinearLayout.LayoutParams oLp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);

    oLl.addView(oNum);
    oLl.addView(oText,oLp);

    oContainer.addView(oLl,oLp);

But It cuts the last line. 但这切到了最后一行。

在此处输入图片说明

EDIT: 编辑:

The code of the Radio Buttons: 单选按钮的代码:

 RadioGroup oRg = new RadioGroup(getContext());
    oRg.setOrientation(RadioGroup.HORIZONTAL);
    oRg.setPadding(Dp_to_Px(10),Dp_to_Px(6),0,0);

    RadioButton oRbSi = new RadioButton(getContext());
    oRbSi.setText(getContext().getString(R.string.Si));
    oRbSi.setPadding(0,0,Dp_to_Px(25),Dp_to_Px(5));

    RadioButton oRbNo = new RadioButton(getContext());
    oRbNo.setText(getContext().getString(R.string.No));

    oRg.addView(oRbSi);
    oRg.addView(oRbNo);

    oContainer.addView(oRg);

And the oContainer definition: 和oContainer定义:

<LinearLayout
    android:id="@+id/encuesta_frg_contaier"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

</LinearLayout>

It is because of this: oNum.setPadding(Dp_to_Px(10),Dp_to_Px(15),0,0); 因为这个原因: oNum.setPadding(Dp_to_Px(10),Dp_to_Px(15),0,0);

The oNum TextView has padding on the top, which is pushing the oText TextView below the oRg RadioGroup. oNum TextView在顶部具有填充,这oText TextView推到oRg RadioGroup下方。 Try setting the padding on oLl instead, and your issue should be solved. 尝试在oLl上设置填充,这样就可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM