SlidingDrawer half open at startup

I’m working on a part of my application, and I was wondering if it’s possible to partially open the Sliding Box and not completely close so that the user can peak in the text content before clicking the “Show More” button, which can show the rest of the text.

Thanks in advance.

+3
source share
4 answers

I had a similar problem, and I finished modifying SlidingDrawer to show some of the content when the drawer is minimized / closed. Using SemiClosedSlidingDrawer you specify how much of the content screen should be displayed in folded / closed mode with the dimension attribute "semiClosedContentSize":

<se.smartrefill.view.SemiClosedSlidingDrawer 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:custom="http://schemas.android.com/apk/res/se.smartrefill.app.x"
    android:id="@+id/mySlidingDrawer"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    custom:orientation="horizontal"
    custom:handle="@+id/handle"
    custom:content="@+id/content"
    custom:allowSingleTap="true"
    custom:semiClosedContentSize="40dp"
    >

attrs.xml( res/values ​​/) :

<declare-styleable name="SemiClosedSlidingDrawer">
    <attr name="handle" format="integer"/>
    <attr name="content" format="integer"/>
    <attr name="orientation" format="string" />
    <attr name="bottomOffset" format="dimension"  />
    <attr name="topOffset" format="dimension"  />
    <attr name="allowSingleTap" format="boolean" />
    <attr name="animateOnClick" format="boolean" />
    <attr name="semiClosedContentSize" format="dimension" />
</declare-styleable>

"se.smartrefill.app.x" , AndroidManifest.

SlidingDrawer (. ) , / 40dp ( fill_parent high). / , SlidingDrawer, / ( semiClosedContentSize = "0dp", SlidingDrawer). SlidingDrawer Android-4 ( "1,6" ), (.) Android-14 ( "4.0" ). Android ( SlidingDrawer API 4 API 14). .

!

, Jacob

+8

, . ( ) , . , , .

:

<RelativeLayout
  android:id="@+id/drawerContainer"
  android:layout_alignParentRight="true"
  android:layout_width="120dp"
  android:layout_height="match_parent">
  <SlidingDrawer
    android:id="@+id/drawer"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:handle="@+id/handle"
    android:content="@+id/content">
    <ImageView
      android:id="@+id/handle"
      android:layout_width="20dip"
      android:layout_height="match_parent"
      android:src="@drawable/drawer_handle />
    <LinearLayout
      android:id="@+id/content"
      android:layout_width="wrap_content"
      android:layout_height="match_parent"
      android:orientation="horizontal">
      <ListView
        android:id="@+id/list"
        android:layout_width="100dp"
        android:layout_height="match_parent">
      </ListView>
      <ImageView
        android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone">
      </ImageView>
    </LinearLayout>
  </SlidingDrawer> 
</RelativeLayout>

, . OnItemClickListener :

private OnItemClickListener onItemClickListener = new OnItemClickListener() {

  @Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {     

    if (imageView.getVisibility() == View.GONE) {     
      ExpandViewAnimation animation = new ExpandViewAnimation(drawerContainer, ((View) drawerContainer.getParent()).getWidth());
      animation.setDuration(500);
      drawerContainer.setAnimation(animation);
      animation.start();
      imageView.setVisibility(View.VISIBLE);
    }
    //code for displaying an image in the imageview
  }  
};

, , . :

public class ExpandViewAnimation extends Animation {
  int targetWidth;
  int initialWidth;
  View view;

  public ExpandViewAnimation(View view, int targetWidth) {
    this.view = view;
    this.targetWidth = targetWidth;
    initialWidth = view.getWidth();
  }

  @Override
  protected void applyTransformation(float interpolatedTime, Transformation t) {

    int newWidth = initialWidth + (int) ((targetWidth - initialWidth) * interpolatedTime);

    LayoutParams lp = new LayoutParams((LayoutParams) view.getLayoutParams());
    lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    view.setLayoutParams(lp);

    view.getLayoutParams().width = newWidth;
    view.requestLayout();

    if (newWidth == targetWidth) {
      LayoutParams matchParentParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
      view.setLayoutParams(matchParentParams);
      view.clearAnimation();
    }
  }

  @Override
  public void initialize(int width, int height, int parentWidth, int parentHeight) {
    super.initialize(width, height, parentWidth, parentHeight);
  }

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

, , , ( ) onDrawerClose:

private OnDrawerCloseListener onDrawerCloseListener = new OnDrawerCloseListener() {

  @Override
  public void onDrawerClosed() {
    imageView.setVisibility(View.GONE);
    imageView.setImageDrawable(null);  
    drawerContainer.setLayoutParams(initialLayoutParams);  
  }
};

, , onTouchListener.

: , , . , .

+1

, - , -

 <SlidingDrawer android:layout_height="wrap_content"
             android:handle="@+id/handle" 
             android:content="@+id/content"
             android:id="@+id/slide" 
             android:orientation="vertical"
             android:layout_width="fill_parent">
    <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content"...>
       <Button android:id="@+id/ShowMore"... />
       <LinearLayout android:id="@+id/More" android:visibility="gone" ...>
           ... more stuff
       </LinearLayout>

    </LinearLayout>
</SlidingDrawer>

ShowMore "" View.GONE View.VISIBLE

** : , : " ", " ". , ? , ? () , , +, "", , .

0

I recently developed an application in which I had a requirement that you required. By googling, I found that we changed the source code of the original sliding box. I did this and all the modified code with me, I tried and it works fine. I can send you the whole file. Just tell me your email id.
you will also need attrs.xml in the values ​​folder of your project where you want to use this code. The attrs.xml code is located below.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="SlidingDrawer">
        <attr name="handle" format="integer"/>
        <attr name="content" format="integer"/>
    </declare-styleable>
</resources>

Hope this helps you.

0
source

All Articles