Headertab

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Saturday 12 March 2016

ExpandableView

Hello friends today we are study about how to create ExpandableView so lets start..

Create New Android Project

activity_main.xml


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ExpandblePannel="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.samset.expandbleview.MainActivity">


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


        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">


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


                <com.samset.expandbleview.ExpandbleLayout
                    android:id="@+id/expandLayout"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    ExpandblePannel:animationDuration="25"
                    ExpandblePannel:collapsedHeight="50dip"
                    ExpandblePannel:content="@+id/value"
                    ExpandblePannel:handle="@+id/expand">




                    <TextView
                        android:id="@id/value"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="" />


                    <Button
                        android:id="@id/expand"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="More" />




                </com.samset.expandbleview.ExpandbleLayout>


                <LinearLayout
                    android:layout_marginTop="10dp"
                    android:id="@+id/iiii"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">
                    <TextView
                        android:padding="10dp"
                        android:id="@+id/value0"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="Design your custom views" />
                    <TextView
                        android:padding="10dp"
                        android:id="@+id/value1"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="Bottom View 1" />


                    <TextView
                        android:padding="10dp"
                        android:id="@+id/value11"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:textSize="20sp"
                        android:text="Bottom View 2" />


                    <TextView
                        android:padding="10dp"
                        android:id="@+id/value2"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="Bottom View 3" />


                    <TextView
                        android:padding="10dp"
                        android:textSize="20sp"
                        android:id="@+id/value22"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="Bottom View 4" />




                </LinearLayout>
            </LinearLayout>
        </ScrollView>
    </LinearLayout>


</RelativeLayout>


MainActivity.java


public class MainActivity extends AppCompatActivity {
  private ExpandbleLayout expandbleLayout;
    private TextView textView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        expandbleLayout = (ExpandbleLayout)findViewById(R.id.expandLayout);
        textView= (TextView) findViewById(R.id.value);
        textView.setText(Utils.text);


        expandbleLayout.setOnExpandListener(new ExpandbleLayout.OnExpandListener() {
            public void onCollapse(View handle, View content) {
                Button btn = (Button) handle;
                btn.setText("More");
            }


            public void onExpand(View handle, View content) {
                Button btn = (Button) handle;
                btn.setText("Less");
            }
        });
    }
}



Thank you
I hope this blog helps you.If you want full source code click below link

Source code

https://github.com/SamsetDev/ExpandableView




No comments:

Post a Comment