Neeraj Kumar
Neeraj Kumar

Reputation: 655

Create dynamic layout

I am Android beginner, I am developing an app for college in which I need to schedule the class timing for the teacher, data come from a server but I don't know, how many subject allocated for a teacher, therefore I need to create this layout dynamically like this... layout

Upvotes: 0

Views: 76

Answers (2)

Sonal Bharwani
Sonal Bharwani

Reputation: 61

I guess you are talking about that textview with green background. For that you need to first create drawable folder in your project's res folder then craete one xml file in that folder like this

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <solid android:color="@color/ur_color"/>

    <corners android:topLeftRadius="180dp"
        android:topRightRadius="180dp"
        android:bottomLeftRadius="180dp"
        android:bottomRightRadius="180dp"/>

</shape> 

then set this drawable as a background of that textview lets say this file name is bg_txt.xml then u have to write in the property of textview

android:background="@drawable/bg_txt">

Upvotes: 1

AskNilesh
AskNilesh

Reputation: 69681

try this create your layout like this

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <LinearLayout
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:textStyle="bold"
            android:padding="10dp"
            android:layout_height="wrap_content"
            android:text="Android"
            android:textColor="#000" />
        <TextView
            android:layout_width="match_parent"

            android:padding="10dp"
            android:layout_height="wrap_content"
            android:text="9:30 AM - 10:30 Am"
            />

    </LinearLayout>

       <TextView
        android:padding="5dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center"
        android:background="@drawable/custom_button"
        android:text="1" />

</LinearLayout>

create custom_button like this in drawable folder

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="oval">
        <stroke android:width="2dp" android:color="@color/colorPrimary" />
        <solid android:color="@color/colorPrimary"/>
    </shape>
</item>

Upvotes: 0

Related Questions