Android在Radio组中包裹多个按钮

时间:2019-01-13 05:41:26

标签: android android-radiogroup

我有一个RadioGroup,并且在代码中我添加了toggleButton,如何包装按钮,使它们进入下一行而不隐藏在屏幕之外?

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final RadioGroup buttonLayout = (RadioGroup) findViewById(R.id.rdc_debug_endpoint_radio_group_buttons);

        for (int i = 0; i<=10; i++) {
            ToggleButton toggleButton = new ToggleButton(this);
            toggleButton.setTextOn("Hello ");
            toggleButton.setTextOff("Hello ");
            toggleButton.setText("Hello " + i);
            toggleButton.setTextSize(10);
            buttonLayout.addView(toggleButton);
        }

    }
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <RadioGroup
        android:id="@+id/rdc_debug_endpoint_radio_group_buttons"
        android:isScrollContainer="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal|center_vertical"
        android:gravity="center_horizontal"
        android:orientation="horizontal"></RadioGroup>


</android.support.constraint.ConstraintLayout>

android not wrapping

如何包装其余4到10个按钮?

0 个答案:

没有答案