【问题标题】:Need to Dynamically Set Radio Button horizontaly in a layout :android需要在布局中水平动态设置单选按钮:android
【发布时间】:2013-04-17 17:01:19
【问题描述】:

我需要在布局中动态设置单选按钮,但是当我水平添加它时,它将能够在单行中显示单选按钮,因此我的所有单选按钮都不可见,我需要设置休息单选按钮从下到上单选按钮,意味着所有按钮都应该在水平方向可见,除了单选按钮的左侧之外还有文本.. 我的代码在下面,但它在一行中显示单选按钮,因此所有单选按钮都不可见..

main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
    android:id="@+id/TextView01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Choose Your Favorite Actress" >
</TextView>

<RadioGroup
    android:id="@+id/RadioGroup01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
</RadioGroup>
<Button
    android:id="@+id/Button01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Submit" >
</Button>

 </LinearLayout>

而java类是:

 @Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


    DisplayRadioButton();

}


public void DisplayRadioButton()
{
    for(int i=0;i<10;i++)
    {
        RadioGroup radiogroup = (RadioGroup)findViewById(R.id.RadioGroup01);
        RadioButton rdbtn = new RadioButton(this);
        rdbtn.setId(i);
        rdbtn.setText(text[i]);
        radiogroup.addView(rdbtn);
    }

}

【问题讨论】:

    标签: android layout radio-button


    【解决方案1】:

    radgroup.layout(l, t, r, b);左上右下位置

    【讨论】:

      猜你喜欢
      • 2013-02-06
      • 2015-08-11
      • 2011-06-08
      • 2014-10-14
      • 2021-12-10
      • 2013-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多