1

I have a RadioGroup and in code I am adding toggleButton, How can I wrap the buttons so that they come to the next line and do not hide off screen?

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

How do I wrap the remaining buttons 4 to 10?

Yahoo
  • 4,093
  • 17
  • 59
  • 85
  • For this you need to try something like [This](https://stackoverflow.com/questions/4474237/how-can-i-do-something-like-a-flowlayout-in-android) .. – ADM Jan 13 '19 at 06:18
  • @ADM, I tried to wrap it but it does not work, any tips? – Yahoo Jan 21 '19 at 18:08
  • There is no layout in Android which provide this arrangement . So you should use the link above . And make it like radio group by code . I.e One selection at a time . Only if I understood correctly .. – ADM Jan 21 '19 at 18:15

0 Answers0