2016-12-05 53 views
-3

工作我使用ExpandableLayout从这个库:ExpandableLayout不是在Android的6

https://github.com/traex/ExpandableLayout

其工作良好,但在Android的6这是行不通的!只显示我的数据和不可点击的布局。在我的项目 这里

我输入库的代码库我使用它:

 import android.content.Context; 
    import android.content.res.TypedArray; 
    import android.os.Build; 
    import android.os.Handler; 
    import android.util.AttributeSet; 
    import android.view.View; 
    import android.view.ViewGroup; 
    import android.view.animation.Animation; 
    import android.view.animation.Transformation; 
    import android.widget.FrameLayout; 
    import android.widget.RelativeLayout; 
    public class ExpandableLayout extends RelativeLayout 
    { 
    private Boolean isAnimationRunning = false; 
    private Boolean isOpened = false; 
    private Integer duration; 
    private FrameLayout contentLayout; 
    private FrameLayout headerLayout; 
    private Animation animation; 

    public ExpandableLayout(Context context) 
    { 
     super(context); 
    } 

    public ExpandableLayout(Context context, AttributeSet attrs) 
    { 
     super(context, attrs); 
     init(context, attrs); 
    } 

    public ExpandableLayout(Context context, AttributeSet attrs, int defStyle) 
    { 
     super(context, attrs, defStyle); 
     init(context, attrs); 
    } 

    private void init(final Context context, AttributeSet attrs) 
    { 
     final View rootView = View.inflate(context, R.layout.view_expandable, this); 
     headerLayout = (FrameLayout) rootView.findViewById(R.id.view_expandable_headerlayout); 
     final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ExpandableLayout); 
     final int headerID = typedArray.getResourceId(R.styleable.ExpandableLayout_el_headerLayout, -1); 
     final int contentID = typedArray.getResourceId(R.styleable.ExpandableLayout_el_contentLayout, -1); 
     contentLayout = (FrameLayout) rootView.findViewById(R.id.view_expandable_contentLayout); 

     if (headerID == -1 || contentID == -1) 
      throw new IllegalArgumentException("HeaderLayout and ContentLayout cannot be null!"); 

     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.CUPCAKE) { 
      if (isInEditMode()) 
       return; 
     } 

     duration = typedArray.getInt(R.styleable.ExpandableLayout_el_duration, getContext().getResources().getInteger(android.R.integer.config_shortAnimTime)); 
     final View headerView = View.inflate(context, headerID, null); 
     headerView.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); 
     headerLayout.addView(headerView); 
     final View contentView = View.inflate(context, contentID, null); 
     contentView.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 
     contentLayout.addView(contentView); 
     contentLayout.setVisibility(GONE); 
     headerLayout.setOnClickListener(new OnClickListener() 
     { 
      @Override 
      public void onClick(View v) 
      { 
       if (!isAnimationRunning) 
       { 
        if (contentLayout.getVisibility() == VISIBLE) 
         collapse(contentLayout); 
        else 
         expand(contentLayout); 

        isAnimationRunning = true; 
        new Handler().postDelayed(new Runnable() 
        { 
         @Override 
         public void run() 
         { 
          isAnimationRunning = false; 
         } 
        }, duration); 
       } 
      } 
     }); 

     typedArray.recycle(); 
    } 

    private void expand(final View v) 
    { 
     v.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 
     final int targetHeight = v.getMeasuredHeight(); 
     v.getLayoutParams().height = 0; 
     v.setVisibility(VISIBLE); 

     animation = new Animation() 
     { 
      @Override 
      protected void applyTransformation(float interpolatedTime, Transformation t) 
      { 
       if (interpolatedTime == 1) 
        isOpened = true; 
       v.getLayoutParams().height = (interpolatedTime == 1) ? LayoutParams.WRAP_CONTENT : (int) (targetHeight * interpolatedTime); 
       v.requestLayout(); 
      } 


      @Override 
      public boolean willChangeBounds() { 
       return true; 
      } 
     }; 
     animation.setDuration(duration); 
     v.startAnimation(animation); 
    } 

    private void collapse(final View v) 
    { 
     final int initialHeight = v.getMeasuredHeight(); 
     animation = new Animation() 
     { 
      @Override 
      protected void applyTransformation(float interpolatedTime, Transformation t) { 
       if(interpolatedTime == 1) 
       { 
        v.setVisibility(View.GONE); 
        isOpened = false; 
       } 
       else{ 
        v.getLayoutParams().height = initialHeight - (int)(initialHeight * interpolatedTime); 
        v.requestLayout(); 
       } 
      } 

      @Override 
      public boolean willChangeBounds() { 
       return true; 
      } 
     }; 

     animation.setDuration(duration); 
     v.startAnimation(animation); 
    } 

    public Boolean isOpened() 
    { 
     return isOpened; 
    } 

    public void show() 
    { 
     if (!isAnimationRunning) 
     { 
      expand(contentLayout); 
      isAnimationRunning = true; 
      new Handler().postDelayed(new Runnable() 
      { 
       @Override 
       public void run() 
       { 
        isAnimationRunning = false; 
       } 
      }, duration); 
     } 
    } 

    public FrameLayout getHeaderLayout() 
    { 
     return headerLayout; 
    } 

    public FrameLayout getContentLayout() 
    { 
     return contentLayout; 
    } 

    public void hide() 
    { 
     if (!isAnimationRunning) 
     { 
      collapse(contentLayout); 
      isAnimationRunning = true; 
      new Handler().postDelayed(new Runnable() 
      { 
       @Override 
       public void run() 
       { 
        isAnimationRunning = false; 
       } 
      }, duration); 
     } 
    } 

    @Override 
    public void setLayoutAnimationListener(Animation.AnimationListener animationListener) { 
     animation.setAnimationListener(animationListener); 
    } 
} 

,并在那里我使用这个库

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


        <expandablelayout.library.ExpandableLayout 
       xmlns:expandable="http://schemas.android.com/apk/res-auto" 
       android:id="@+id/firstshahr" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       expandable:el_headerLayout="@layout/view_headershahr" 
       expandable:el_contentLayout="@layout/view_contentshahr" 
       android:layout_marginBottom="10dp" 
       /> 
      <expandablelayout.library.ExpandableLayout 
      android:id="@+id/firststar" 
       xmlns:expandable="http://schemas.android.com/apk/res-auto" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      expandable:el_headerLayout="@layout/view_headerstar" 
      expandable:el_contentLayout="@layout/view_contentstar" 
      android:layout_marginBottom="10dp" 
      /> 
      <expandablelayout.library.ExpandableLayout 
       android:id="@+id/firsttarikh" 
       xmlns:expandable="http://schemas.android.com/apk/res-auto" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       expandable:el_headerLayout="@layout/view_headertarikh" 
       expandable:el_contentLayout="@layout/view_contenttarikh" 
       android:layout_marginBottom="10dp" 
       /> 
      <expandablelayout.library.ExpandableLayout 
      android:id="@+id/firstghaza" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      expandable:el_headerLayout="@layout/view_headerghaza" 
      expandable:el_contentLayout="@layout/view_contentghaza" 
      android:layout_marginBottom="10dp" 
      /> 
      <expandablelayout.library.ExpandableLayout 
      android:id="@+id/firsthavapeymaei" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      expandable:el_headerLayout="@layout/view_headerhavapeymaei" 
      expandable:el_contentLayout="@layout/view_contenthavapeyaei" 
       android:layout_marginBottom="10dp" 
      /> 
      <expandablelayout.library.ExpandableLayout 
      android:id="@+id/firstmodat" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      expandable:el_headerLayout="@layout/view_headermodat" 
      expandable:el_contentLayout="@layout/view_contentmodat" 
       android:layout_marginBottom="10dp" 
      /> 

</LinearLayout> 

view_headerstar.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 



    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="40dp" 
     android:id="@+id/header_text" 
     android:gravity="right" 
     android:contextClickable="true"> 



     <TextView 
      android:id="@+id/turlahzeakhari" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp" 
      android:text="درجه هتل" 
      android:textColor="#ffffff" 
      android:textStyle="bold" /> 

     <ImageView 
      android:id="@+id/tour_index" 
      android:layout_width="20dp" 
      android:layout_height="20dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp" 
      android:src="@mipmap/archive_star" 
      /> 
    </LinearLayout> 

    <ImageView 
     android:id="@+id/tour_index55" 
     android:layout_width="14dp" 
     android:layout_height="14dp" 
     android:src="@mipmap/archive_fp" 
     android:layout_gravity="left" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_marginLeft="10dp" 
     android:layout_marginTop="15dp"/> 


</RelativeLayout> 

view_contentstar.xml

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/re12" 
    > 

    <ListView 
     android:paddingBottom="10dp" 
     android:id="@+id/listfilter" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginTop="0dp" 
    android:divider="@color/list_divider" 
    android:dividerHeight="0dp" 
    android:gravity="right" 
    android:layoutDirection="rtl" 
    android:listSelector="@drawable/list_row_selector" 
    android:textAlignment="gravity" 
    android:textDirection="rtl" > 
    </ListView> 

</RelativeLayout> 

回答

0

检查this这是非常简单和有用的!

+0

谢谢,但我想解决我与这个图书馆的问题 – zahra