Giter Club home page Giter Club logo

expandablelayout's Introduction

ExpandableLayout

A expandable Layout to save space and reduce jump between Activity and Fragment ####

USE

Project

It had been used in project KnowWeather,you can learn more.

SimpleUse

intro

Use in RecyclerView

parent view scroll automatically if the view expand out of device screen,

(当展开时如果超过屏幕的高度时父控件自动上移)

intro

Use in ListView

parent view not scroll automatically if the view expand out of device screen

(当展开时如果超过屏幕的高度时父控件不自动上移)

intro

(It runs smoothly, but gif is not appear well) sample.apk

Attention

scroll automatically function not perform well in listview so far.but it perform well in RecyclerView

Adding to your project

This library is available through JitPack.

Step 1. Add the JitPack repository to your build file

gradle

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

maven

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

Step 2. Add the dependency

gradle

compile 'com.github.SilenceDut:ExpandableLayout:1.2.0'

maven

<dependency>
    <groupId>com.github.SilenceDut</groupId>
    <artifactId>ExpandableLayout</artifactId>
    <version>{latest-version}</version>
</dependency>

Basic Usage

Supported Attributes

attr default mean
expDuration 300 expand duration.
expWithParentScroll false parent view should scroll automatically if the view expand out of device screen(当展开时如果超过屏幕的高度是父控件否自动上移).
expExpandScrollTogether false parent view should scroll together with view expanding.
ExpandableLayout inherited from LinearLayout,and the default Orientation is VERTICAL
<com.silencedut.expandablelayout.ExpandableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:expWithParentScroll="true"
    app:expDuration = "300"
    app:expExpandScrollTogether = "false"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <layout1
    ...
    />
    
    <layout2
    ...
    />

</com.silencedut.expandablelayout.ExpandableLayout>

License

Copyright 2015-2016 SilenceDut

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

expandablelayout's People

Contributors

silencedut avatar tomafc330 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

expandablelayout's Issues

expWithParentScroll, CardView, and RecyclerView: Incorrect Collapse Behavior

If you look in app/src/main/res/layout/row.xml of the attached project, you will see that I use ExpandableLayout in a row for a RecyclerView, and I have app:expWithParentScroll="true" set. However, the ExpandableLayout is wrapped in a CardView.

When you run the app, expanding and collapsing a row does not return the row to its original state:

expandablelayout-bug

If you comment out the CardView, ExpandableLayout works correctly:

expandablelayout-bug2

It feels like ExpandableLayout does not like being wrapped in something else for the row, like the CardView. I do not know if it is a bug, a known limitation, or if I am doing something wrong with the CardView somehow.

ExpandableRow.zip

Thanks!

展开时父控件自动上移

自动上移后,当再次点击当前条目或进行滑动时,界面会跳回展开前的位置(listview中使用)

Child View Did not Show Full Content

Hy i have some bug in this library. Some Item in RecyclerView, after it scrolled it did not show full of its view. Some other item in other position just fine.

here the screenshot ( Blue Background is the Header, White ones is the Child )

bug

Choose expanable child view.

I am thinking about selecting child view to expandable. Right now I see that first child view is always visible and second view is dynamic.

I want that second view should be static and first child of view should expandable.

Recycle View scrolls slow. How to fix it ?

Hello,
I just implemented expandable layout in recycle view .
Data coming from web-service and passing array-list through adapter.
Layout row file in Nested Linear Layouts. (may be its layouts load but I tried with Constraint layout . No Effect)
I am still finding the issue !
I am replacing view during expansion and collapse item view (I already commented that code. but still my recycle view is slow )
There is no use of any image storing in itemview .
Help me to fix this issue.

ss1

for more details about question
https://stackoverflow.com/questions/45790906/recycle-view-scrolls-slow-how-to-fix-it

`public class PendingOrdersAdapter extends RecyclerView.Adapter<PendingOrdersAdapter.ViewHolder> {

public LayoutInflater mInflater;
public HashSet<Integer> mExpandedPositionSet = new HashSet<>();
Context context;
ArrayList<CustomerDetails> list;


public PendingOrdersAdapter(Context context, ArrayList<CustomerDetails> list) {
    this.context = context;
    this.list = list;
    this.mInflater = LayoutInflater.from(context);
}

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View item = mInflater.inflate(R.layout.pending_order_item, parent, false);
    return new ViewHolder(item);
}


@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {

    holder.updateItem(position, holder);
    holder.tvOrderNo.setText("" + list.get(position).getOrderID());
    holder.tvCustomerName.setText("" + list.get(position).getCustomerName());
    holder.tvTotalPrice.setText("" + list.get(position).getTotalPrice());
    holder.tvCustomerContactNo.setText("" + list.get(position).getPrimaryContactNo());
    holder.tvProductWeight.setText("" + list.get(position).getProductWeight());
    holder.tvCustomerStatus.setText("" + list.get(position).getCustomerStatus());
    holder.tvDeliveryManStatus.setText("" + list.get(position).getDeliveryManStatus());
    holder.tvAddress.setText("" + list.get(position).getAddress());
    holder.tvDeliveryMan.setText("" + list.get(position).getCustomerName() + " ( " + list.get(position).getPrimaryContactNo() + " ) ");
    holder.tvTime.setText("" + list.get(position).getTime());
    holder.tvPickUpDate.setText("" + list.get(position).getPickupDate());

    holder.tvDeliveryCharge.setText("" + list.get(position).getDeliveryCharge());
  /*  cusLocation = list.get(position).getCusLocation();
    boLocation = list.get(position).getBoLocation();*/
  
  
  //Opening DialogFragment on Click Listner

    holder.tvDeliveryMan.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AppCompatActivity activity = (AppCompatActivity) (context);

            android.app.FragmentTransaction ft = activity.getFragmentManager().beginTransaction();
            android.app.Fragment prev = activity.getFragmentManager().findFragmentByTag("dvdialog");
     
            if (prev != null) {
                ft.remove(prev);
            }
            ft.addToBackStack(null);

            DeliveryManDetailsDialog newFragment = new DeliveryManDetailsDialog();
            newFragment.show(ft, "dvdialog");

        }
    });

    holder.tvAddress.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            final int DRAWABLE_RIGHT = 2;

            
            //Address icon click listner right side
            
            if (event.getAction() == MotionEvent.ACTION_UP) {
                if (event.getRawX() >= (holder.tvAddress.getRight() - holder.tvAddress.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {

                    // your action here
                    Intent intent = new Intent(context, RouteActivity.class);
                    intent.putExtra("custLat", list.get(position).getCustLatitude());
                    intent.putExtra("custLong", list.get(position).getCustLongitude());
                    intent.putExtra("boLat", list.get(position).getBoLatitude());
                    intent.putExtra("boLong", list.get(position).getBosLongitude());

                    context.startActivity(intent);


                }


                return true;

            }
            return true;
        }
    });


}

@Override
public int getItemViewType(int position) {
    return position;
}

@Override
public int getItemCount() {
    return list.size();
}

public void registerExpand(int position, ViewHolder holder) {
    
    if (mExpandedPositionSet.contains(position)) {
        
        //Replacing views at runtime and arrow animation
        
        ViewGroupUtils.replaceView(holder.timeLayout, holder.statusLayout);
        
        holder.orderbox.setBackgroundResource(R.drawable.box_fill_drawable);
        holder.ivArrow.animate().rotation(360).start();
        removeExpand(position);

       


    } else {
        ViewGroupUtils.replaceView(holder.statusLayout, holder.timeLayout);
        
        holder.orderbox.setBackgroundResource(R.drawable.box_fill_drawable_top);
        holder.ivArrow.animate().rotation(180).start();
        addExpand(position);


    }
}

public void removeExpand(int position) {


    mExpandedPositionSet.remove(position);


}

public void addExpand(int position) {


    mExpandedPositionSet.add(position);

}

public class ViewHolder extends RecyclerView.ViewHolder {
    public ExpandableLayout expandableLayout;
    public LinearLayout orderbox, orderbox_bottom;
    public ImageView ivArrow;
    public TextView tvAddress, tvOrderNo, tvCustomerName, tvTotalPrice, tvCustomerContactNo;
    public TextView tvProductWeight, tvCustomerStatus, tvDeliveryManStatus;
    public TextView tvDeliveryCharge, tvDeliveryMan, tvTime;
    public TextView tvPickUpDate;
    public LinearLayout statusLayout, statusParentLayout, timeLayout, timeParentLayout, addressLayout;


    public ViewHolder(final View itemView) {
        super(itemView);
        expandableLayout = (ExpandableLayout) itemView.findViewById(R.id.expandable_layout);
        orderbox = (LinearLayout) itemView.findViewById(R.id.orderbox);

        orderbox_bottom = (LinearLayout) itemView.findViewById(R.id.orderbox_bottom);
        ivArrow = (ImageView) itemView.findViewById(R.id.ivArrow);

        tvOrderNo = (TextView) itemView.findViewById(R.id.tvOrderNo);
        tvCustomerName = (TextView) itemView.findViewById(R.id.tvCustomerName);
        tvTotalPrice = (TextView) itemView.findViewById(R.id.tvTotalPrice);
        tvCustomerContactNo = (TextView) itemView.findViewById(R.id.tvCustomerContactNo);
        tvProductWeight = (TextView) itemView.findViewById(R.id.tvProductWeight);
        tvCustomerStatus = (TextView) itemView.findViewById(R.id.tvCustomerStatus);
        tvDeliveryManStatus = (TextView) itemView.findViewById(R.id.tvDeliveryManStatus);
        tvDeliveryCharge = (TextView) itemView.findViewById(R.id.tvDeliveryCharge);
        tvAddress = (TextView) itemView.findViewById(R.id.tvAddress);
        tvDeliveryMan = (TextView) itemView.findViewById(R.id.tvDeliveryMan);
        tvTime = (TextView) itemView.findViewById(R.id.tvTime);
        tvPickUpDate = (TextView) itemView.findViewById(R.id.tvPickUpDate);

        statusParentLayout = (LinearLayout) itemView.findViewById(R.id.statusParentLayout);
        statusLayout = (LinearLayout) itemView.findViewById(R.id.statusLayout);
        timeParentLayout = (LinearLayout) itemView.findViewById(R.id.timeParentLayout);
        timeLayout = (LinearLayout) itemView.findViewById(R.id.timeDateLayout);
        addressLayout = (LinearLayout) itemView.findViewById(R.id.addressLayout);
    }

    public void updateItem(final int position, final ViewHolder holder) {
        holder.orderbox.setBackgroundResource(R.drawable.box_fill_drawable_top);
        holder.expandableLayout.setOnExpandListener(new ExpandableLayout.OnExpandListener() {
            @Override
            public void onExpand(boolean expanded) {

                registerExpand(position, holder);

            }
        });

        expandableLayout.setExpand(mExpandedPositionSet.contains(position));

    }
}

}`

layout is not expanding programmatically

I have a RecyclerView which have dynamic contents, and i have animation for showing the items.
i try to expand the last layout that i have by code, using expandedItems.expand(), expandedItems.toggle(), expandedItems.performClick(), expandedItems.setExpand(true).

but nothing is working, can you please help in this

it only works if i delay the expand until the animation is finished, is there a way to fix it without handling the animation listener?

里面包裹recyclerview无效的一个场景

里面包裹一个recyclerview,recyclerview的水平滑动的app:layoutManager="android.support.v7.widget.LinearLayoutManager" ,android:orientation="horizontal",
adapter里面item的布局高度不能写死固定值,使用match_parent或者wrap_content,
展开后recyclerview没有绘制出来......

Different item expanded

I'm using an expanded item row. and I make the material dialog appear when the button in it is clicked. but when the dialog closes, the item row on the two above the listener is expanding. ?

RecyclerView for parents and another RecyclerView for children

I applied your library with json data, and it's working perfectly, but the RecyclerView right now is for a list of parents with fixed-size children, but for the json that I'm working on, there's a list for the children themselves.. so how can I accomplish that..!?

do I add recyclerview inside the layout#2 (child) within the ExpanalbeLayout widget..!? if it's gonna work, would show me how, in simple steps..!

thnx

onItemLongClickListener

I like this library. I was wondering though, is there a way to set onItemLongClickListener on ListView with expandable items?

I tried mListView.setOnItemLongClickListener(myOnItemLongClickListener);
but long clicks are not registered

Expand item

hi,
How can I expand an item permanently?
Thank you.

Close views

If any views are expanded, i need to close when i expand one item.Means expand one view at a item. Is it possible?

Dynamically added content cut off

If I dynamically add content to my ExpandableLayout, it keeps the height of it when it was instantiated via XML. Is there some way to update the height of the ExpandableLayout when I have added the dynamic content or is there another way I can do this?

Collapsed:

before

Expanded:

after

As you can see in the first item, there is white space when I want it to end after "Outbound". The second item gets cut off. So it seems that the dynamic changes are being ignored.

EDIT:

My ExpandableLayout XML:

<?xml version="1.0" encoding="utf-8"?>
<com.silencedut.expandablelayout.ExpandableLayout
    android:id="@+id/lytExpandableLayout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:expDuration="300"
    app:expExpandScrollTogether="false"
    app:expWithParentScroll="true"
    custom:layout_constraintLeft_toLeftOf="parent"
    custom:layout_constraintRight_toRightOf="parent"
    custom:layout_constraintTop_toTopOf="parent">

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

        <customviews.FontText
            android:id="@+id/tvTicketHeader"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginTop="20dp"
            android:includeFontPadding="false"
            android:text=""
            android:textAllCaps="true"
            android:textColor="#2a2a2a"
            android:textSize="20sp"
            custom:layout_constraintLeft_toLeftOf="parent"
            custom:layout_constraintTop_toTopOf="parent"/>

        <customviews.FontText
            android:id="@+id/tvRoute"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:text="Route"
            android:textAllCaps="true"
            android:textColor="#c2c2c2"
            android:visibility="gone"
            custom:layout_constraintLeft_toLeftOf="parent"
            custom:layout_constraintTop_toBottomOf="@+id/tvTicketHeader"
            />

        <customviews.FontText
            android:id="@+id/tvRouteDescription"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginTop="8dp"
            android:includeFontPadding="false"
            android:text=""
            android:textColor="#2a2a2a"
            android:textSize="14sp"
            custom:layout_constraintLeft_toLeftOf="parent"
            custom:layout_constraintTop_toBottomOf="@+id/tvRoute"/>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/lytRestrictions"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:orientation="vertical"
        android:visibility="visible">

        <LinearLayout
            android:id="@+id/lytOutboundRestrictions"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <customviews.FontText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Restriction Code: "
                android:textAllCaps="true"
                android:textColor="#c2c2c2"
                android:textSize="14sp"/>

            <customviews.FontText
                android:id="@+id/tvRestrictionCode"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAllCaps="true"
                android:textColor="#c2c2c2"
                android:textSize="14sp"/>

        </LinearLayout>

        <LinearLayout
            android:id="@+id/lytInboundRestrictions"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <customviews.FontText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Outbound: "
                android:textColor="#2a2a2a"
                android:textSize="14sp"/>

            <customviews.FontText
                android:id="@+id/tvOutboundRestriction"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#2a2a2a"
                android:textSize="14sp"/>

        </LinearLayout>

        <LinearLayout
            android:id="@+id/lytInboundRestriction"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:visibility="visible">

            <customviews.FontText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Inbound: "
                android:textColor="#2a2a2a"
                android:textSize="14sp"/>

            <customviews.FontText
                android:id="@+id/tvInboundRestriction"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#2a2a2a"
                android:textSize="14sp"/>

        </LinearLayout>

    </LinearLayout>

</com.silencedut.expandablelayout.ExpandableLayout>

Failed to compile lib on graddle dependencies

I'm trying to add this library in my project, doing exactly what was specified for graddle:

allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}

and

compile 'com.github.SilenceDut:ExpandableLayout:1.0.0'

but always says:
Failed to resolve: com.github.SilenceDut:ExpandableLayout:1.0.1

Am I doing something wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.