-2

Is it possible to create this XML complex view dynamically on a push of a button using android studio

The output is here :

https://ibb.co/hSkP5k

The XML code is given below

I want to create a button to add this bar dynamically at runtime and want to know whether it is possible..I'm new to android studio and would love some advice on this .

Thanks in advance!

<LinearLayout
            android:id="@+id/forsub1"
            android:layout_width="fill_parent"
            android:layout_height="50.0dip"
            android:layout_marginEnd="10.0dip"
            android:layout_marginStart="10.0dip"
            android:layout_marginTop="10.0dip"
            android:background="#ffffff"
            android:orientation="horizontal">

            <TextView
                android:layout_width="30.0dip"
                android:layout_height="fill_parent"
                android:background="@drawable/round"
                android:text="1"
                android:textColor="#ffffffff"
                android:textSize="40.0sp" />

             <EditText
                android:id="@+id/sub1"
                android:layout_width="170.0dip"
                android:layout_height="fill_parent"
                android:inputType="textCapWords"
                android:paddingStart="10.0dip"
                android:textColor="#ff000000"
                android:background="@drawable/blue_bar"
                android:textSize="30.0sp"
                android:textStyle="bold" />

            <Button
                android:id="@+id/present1"
                android:layout_width="50.0dip"
                android:layout_height="fill_parent"
                android:background="@drawable/green"
                android:onClick="present"
                android:textSize="15.0sp" />

            <Button
                android:id="@+id/absent1"
                android:layout_width="50.0dip"
                android:layout_height="fill_parent"
                android:background="@drawable/red"
                android:onClick="absent"
                android:textSize="15.0sp" />

            <Button
                android:id="@+id/stats1"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:background="@drawable/blue_bar"
                android:onClick="stats"
                android:text="0 %"
                android:textSize="15.0sp"
                android:textStyle="bold" />
        </LinearLayout>**strong text

**

2

1 Answer 1

0

Yes, it is possible, but don't try with hardcoded widths. Use weights for ease of designing for multiple devices.

Sign up to request clarification or add additional context in comments.

1 Comment

Please see Why is "Is it possible to..." a poorly worded question? "Yes or no" isn't all that useful to future readers.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.