Slide in (over) activity - java

Currently I'm trying to implement something in my app where I really don't know where to start.
Have a look at this little image:
You can find the app in play store here: https://play.google.com/store/apps/details?id=com.imano.euro2012.row
In my app, I have a listview and when i tap on an item I want to slide in the black activity in to about 3/4. In that activity I want to have some llistview item specific options.
Any one knows how to solve this?
Solution:
Thanks to Imran-Khan I got it working.
But I think this code is not perfect. I'm not sure if the width and height calculation in the first half of the showPopup() method is correct. And in my solution the popup has on the bottom and on the right a little margin. I don't know right now why this happens. Maybe someone can help...
Here is what I did so far:
First I added the method showpopup(long selectedItem) to my listview:
lv_timer.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parentView, View childView, int position, long id) {
showPopup(id);
}
});
and the method itself:
private void showPopup(long selectedItem) {
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
int popupWidth = (width / 4) * 3;
int popupHeight = height;
LinearLayout viewGroup = (LinearLayout) findViewById(R.id.ll_timer_prop);
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.timer_properties, viewGroup);
final PopupWindow popup = new PopupWindow(this);
popup.setContentView(layout);
popup.setWidth(popupWidth);
popup.setHeight(popupHeight);
popup.setFocusable(true);
popup.showAtLocation(layout, Gravity.NO_GRAVITY, width - (width / 4 * 3), 0);
TextView tv_item = (TextView) layout.findViewById(R.id.tv_item);
tv_item.setText("Clicked Item ID: " + selectedItem);
}
This is working fine for me.
for the slide in part I've found this thread: PopupWindow animation not working
I added
popup.setAnimationStyle(R.style.AnimationPopup);
before the showAtLocation() call, created a res/anim directory an created two XML files in it: popup_show.xml and popup_hide.xml
popup_show.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:fromXScale="0.0" android:toXScale="1.0"
android:fromYScale="1.0" android:toYScale="1.0"
android:pivotX="100%" android:pivotY="0%"
android:duration="#android:integer/config_shortAnimTime"
/>
<alpha
android:interpolator="#android:anim/decelerate_interpolator"
android:fromAlpha="0.0" android:toAlpha="1.0"
android:duration="#android:integer/config_shortAnimTime"
/>
</set>
popup_hide.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:fromXScale="1.0" android:toXScale="0.0"
android:fromYScale="1.0" android:toYScale="1.0"
android:pivotX="100%" android:pivotY="0%"
android:duration="#android:integer/config_shortAnimTime"
/>
<alpha
android:interpolator="#android:anim/decelerate_interpolator"
android:fromAlpha="1.0" android:toAlpha="0.0"
android:duration="#android:integer/config_shortAnimTime"
/>
</set>

You can create this view using custom PopupWindow
see this tutorial for Creating Custom PopupWindow
How to create popups in Android

You can use QuickAction For such behaviour, Like shown on third screen
Edit
Sorry I have not paid attention for the fact that you want a sliding from right to left effect, But I think you can try to customise slidindrawer in Android API to make slide from right to left.

Funny, I'm actually looking at the same problem right now.
I've found this topic:
Android Facebook style slide
Some nice examples in there.

Related

Increase height of selected icon in navigation bottom view android when using custom icon?

Please, I want to use custom icon for bottom navigation view in android like this. How to change icon position when selected? When they are selected they go up a bit. Do you create a selected icon with a certain margin or is there a way to set the height in android? This image is from a flutter library though. I want to reproduce that in an Android Java project. Or find a library that implement it
Inside your bottomNavigationView.setOnNavigationItemSelectedListener for each icon pressed call that animation method animateBottomIcon(int itemIndex, boolean isChecked).
BottomNavigationView bottomNav;
BottomNavigationMenuView menuView;
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
bottomNav.setClipChildren(false);
bottomNav.setClipToPadding(false);
bottomNav.setClipToOutline(false);
menuView.setClipChildren(false);
menuView = (BottomNavigationMenuView) bottomNav.getChildAt(0);
}
private void animateBottomIcon(int itemIndex, boolean isChecked) {
final View view = menuView.getChildAt(itemIndex).findViewById(com.google.android.material.R.id.icon);
ObjectAnimator translateUpAnimator = ObjectAnimator.ofFloat(view, "translationY",
0,
(float) (-(bottomNav.getHeight() / 2))).setDuration(500);
if(!isChecked) {
translateUpAnimator.start();
}
if(currentItemIndex != -1) {
final View currentView = menuView.getChildAt(currentItemIndex).findViewById(com.google.android.material.R.id.icon);
ObjectAnimator translateDownAnimator = ObjectAnimator.ofFloat(currentView, "translationY",
0,
(float) (-(bottomNav.getHeight() / 2))).setDuration(500);
if (!isChecked) {
translateDownAnimator.reverse();
}
}
}
Usually the menu icon will be cut off by the BottomNavigation to avoid that use: android:clipChildren="false" on the root view of your layout, and in your java class, inside onCreateView():
bottomNav.setClipChildren(false);
bottomNav.setClipToPadding(false);
bottomNav.setClipToOutline(false);
and most importantly on your menuItem, because it's the parent of your icon items. menuView.setClipChildren(false);.
Remember to give your bottom navigation view a fixed height.
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="56dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_gravity="bottom"
android:background="#color/white"
app:itemIconSize="54dp"
app:elevation="12dp"
app:labelVisibilityMode="unlabeled"
app:menu="#menu/menu_bottom_nav">[![enter image description here][1]][1]
UPDATE: The library is live here https://github.com/Kwasow/BottomNavigationCircles-Android
I stumbled upon your question and created a custom android navigation bar inspired by the design.
The navigation bar looks like this:
The code for it is located here: https://github.com/Kwasow/Archipelago/blob/main/app/src/main/java/com/github/kwasow/archipelago/views/CustomBottomNavigation.kt
The bg_green_circle.xml drawable looks like this:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size
android:width="24dp"
android:height="24dp"/>
<solid android:color="#6CB86A"/>
</shape>
I might turn it into a package in the future, but it still requires some work. I'll update the post if it happens.
You can do this by using a selector.
For this you need two separate images:
1) when state selected is true means your selected image
2) default means when no icon is selected.
XML
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"
android:drawable="#drawable/YOUR SELECTED IMAGE">
</item>
<item android:drawable="#drawable/YOUR DEFAULT IMAGE"></item>
</selector>
Then use this selector as a drawable for each image icon for the bottom navigation view.
You can add other attributes in selector a/c to your requirements.

Using LayoutParams on While loop Java, Android

It seems like I have a problem with java code where I want to use LayoutParams in while loop.
So in this code, I thought it might be like this but not working.
If is width and height of the image > 0 , then start looping by subtracting height and width till 0.
Does anyone have some fix for this?
Here is the code:
public void run() {
ViewGroup.LayoutParams params = myBall.getLayoutParams();
while ((params.height > 0) && (params.width > 0)) {
params.width--;
params.height--;
myBall.setLayoutParams(params);
}}
Ok, try this
Create a folder named anim in your res and add anim_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="250"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0"
android:toYScale="0" >
</scale>
<alpha
android:duration="250"
android:fromAlpha="1"
android:toAlpha="0" />
</set>
do this in your main java,
//Your view could be any View or ViewGroup
View view = (View) findViewById(R.id.view1);
view.setAnimation(AnimationUtils.loadAnimation(context,
R.anim.anim_out));
view.setVisibility(View.GONE);
Try this and tell me :). Happy coding
Try doing it like this:
public void run() {
while ((myBall.getLayoutParams().height > 0) && (myBall.getLayoutParams().width > 0))
{
myBall.getLayoutParams().width--;
myBall.getLayoutParams().height--;
}
}
Let me know if it did the trick.

What is causing this animation flicker and how do I remove it?

I have made a tiny android application to attempt to resolve an issue I've been seeing on a different app. I'm trying to achieve an effect where the TextViewstarts off screen, then scrolls on.
What I did looks like it's working well on my 4.0.4, but when I use the Android Virtual Device (4.1.2) there is a "flicker" showing the TextView in the original place before the animation starts. I've noticed the same thing on a friend's Tablet (4.4).
I uploaded a video to show the issue here.
My layout:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/txtV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
During my MainActivity's onResume() function I move the TextView off screen for a starting position:
#Override
protected void onResume(){
super.onResume();
View v = findViewById(R.id.txtV);
Animation hideWords = AnimationUtils.loadAnimation(getBaseContext(), R.anim.hidetext);
hideWords.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationEnd(Animation animation) {
View v = findViewById(R.id.txtV);
int xOffset = (int)(v.getWidth() * .1);
RelativeLayout.LayoutParams rlParams =
(RelativeLayout.LayoutParams)v.getLayoutParams();
rlParams.setMargins(-1*xOffset, 0, xOffset, 0);
v.setLayoutParams(rlParams);
}
And then there's a Button which just has onClick set to the function animateIt() the source of which is:
public void animateIt(View v){
v = findViewById(R.id.txtV);
AnimationSet as = new AnimationSet(true);
Animation showWords = AnimationUtils.loadAnimation(
getBaseContext(), R.anim.texnation);
as.addAnimation(showWords);
v.startAnimation(as);
}
The animation just slides the View onscreen:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false"
android:duration="700"
android:fillAfter="true"
android:interpolator="#android:anim/linear_interpolator" >
<translate
android:fromXDelta="-100%"
android:toXDelta="0%" />
</set>
So what I'm trying to figure out is what I've done incorrectly here that's causing that flicker. Right after the button is pushed for the first time the text flickers on the screen then it disappears and slides on as expected.
Any ideas?

Programmatically rotate drawable or view [duplicate]

Could anyone tell me how they have got RotateDrawable to work whether it be from code or XML or both? The documentation on animating Drawables is pretty poor and animation only seems to work for images. I want to be able to animate all drawables. When i tried to get a RotateDrawble from XML is just causes an exception. What is the correct function to find a RotateDrawable from XML?
here's a nice solution for putting a rotated drawable for an imageView:
Drawable getRotateDrawable(final Bitmap b, final float angle) {
final BitmapDrawable drawable = new BitmapDrawable(getResources(), b) {
#Override
public void draw(final Canvas canvas) {
canvas.save();
canvas.rotate(angle, b.getWidth() / 2, b.getHeight() / 2);
super.draw(canvas);
canvas.restore();
}
};
return drawable;
}
usage:
Bitmap b=...
float angle=...
final Drawable rotatedDrawable = getRotateDrawable(b,angle);
root.setImageDrawable(rotatedDrawable);
another alternative:
private Drawable getRotateDrawable(final Drawable d, final float angle) {
final Drawable[] arD = { d };
return new LayerDrawable(arD) {
#Override
public void draw(final Canvas canvas) {
canvas.save();
canvas.rotate(angle, d.getBounds().width() / 2, d.getBounds().height() / 2);
super.draw(canvas);
canvas.restore();
}
};
}
also, if you wish to rotate the bitmap, but afraid of OOM, you can use an NDK solution i've made here
You have to animate the "level" property, where 0 is the start value and 10000 is the end value.
The below example animates from start to finish, you can reverse the animation easily with this method.
final RotateDrawable rotateDrawable = ...
ObjectAnimator.ofInt(rotateDrawable, "level", 0, 10000).start();
I would like to add a full example of animating a progress icon on ImageView, it is based on Mark Hetherington answer.
So my animation looks as follows:
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="0"
android:toDegrees="-360"
android:duration="100"
android:drawable="#drawable/ic_loop_black_24dp"
/>
icon comes from https://material.io/icons/
then my layout contains an ImageView as follows:
<ImageView
android:id="#+id/progress"
android:layout_marginTop="0dp"
android:layout_marginLeft="-3dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:visibility="gone"
android:scaleType="fitCenter"
android:background="#drawable/progress_anim"
android:layout_gravity="center_horizontal|center_vertical"
/>
and finally in code when I need to show animation I do:
RotateDrawable rotateDrawable = ((RotateDrawable)progressImage.getBackground());
ObjectAnimator anim = ObjectAnimator.ofInt(rotateDrawable, "level", 0, 10000);
anim.setDuration(1000);
anim.setRepeatCount(ValueAnimator.INFINITE);
anim.start();
RotateDrawable does not seem to be animated. Instead, you have to use setLevel to change the rotation of the drawable.
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/your_drawable"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360" />
And set the level will rotate the drawable:
final ImageView image = (ImageView)findViewById(R.id.imageView1);
final RotateDrawable drawable = (RotateDrawable)image.getDrawable();
drawable.setLevel(500);
The following code returns a Drawable wrapper that rotates another Drawable programmatically:
Drawable rotateDrawable(Drawable d, final float angle) {
// Use LayerDrawable, because it's simpler than RotateDrawable.
Drawable[] arD = {
d
};
return new LayerDrawable(arD) {
#Override
public void draw(Canvas canvas) {
canvas.save();
canvas.rotate(angle);
super.draw(canvas);
canvas.restore();
}
};
}
I haven't worked with a RotateDrawable, but if you're simply trying to animate rotation on a graphic, you don't need it. Drawables with a 'level' like RotateDrawable are meant to convey information rather than animate views.
The following code rotates an ImageView around its center:
ImageView myImageView = (ImageView)findViewById(R.id.my_imageview);
AnimationSet animSet = new AnimationSet(true);
animSet.setInterpolator(new DecelerateInterpolator());
animSet.setFillAfter(true);
animSet.setFillEnabled(true);
final RotateAnimation animRotate = new RotateAnimation(0.0f, -90.0f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f);
animRotate.setDuration(1500);
animRotate.setFillAfter(true);
animSet.addAnimation(animRotate);
myImageView.startAnimation(animSet);
Since you're trying to use Almero's Android Gesture Detectors, I decided to do the same in order to find an appropriate solution:
public class MainActivity extends Activity {
private RotateGestureDetector mRotateDetector;
private float mRotationDegrees = 0.f;
private static final float ROTATION_RATIO = 2;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mRotateDetector = new RotateGestureDetector(getApplicationContext(), new RotateListener());
}
#Override
public boolean onTouchEvent(MotionEvent event) {
mRotateDetector.onTouchEvent(event);
return super.onTouchEvent(event);
}
private class RotateListener extends RotateGestureDetector.SimpleOnRotateGestureListener {
#Override
public boolean onRotate(RotateGestureDetector detector) {
mRotationDegrees -= detector.getRotationDegreesDelta();
ImageView v = (ImageView) findViewById(R.id.imageView);
// For NineOldAndroids library only!
ViewHelper.setRotation(v, mRotationDegrees * ROTATION_RATIO);
// For HONEYCOMB and later only!
v.setRotation(mRotationDegrees * ROTATION_RATIO);
return true;
}
}
}
It works fine for me (I'm able to rotate the ImageView with two-finger rotation gesture.
NOTE: Don't forget to chose appropriate rotation method call. I commented both of them to draw your attention.
ROTATION_RATIO is just a multiplier to speed-up a rotation response on my fingers movement.
You can use any rotation axis (setRotation(), setRotationX() and setRotationY()) methods for a View.
To enable support of this code on Android devices with API Level lower than 11 (pre-Honeycomb devices) you may want to engage NineOldAndroid library.
You could manually call RotatedDrawable.setLevel() to rotate the drawable, or you could read the code of ProgressBar, the indeterminate drawable is a LayerDrawable whose children were RotatedDrawable, like this one:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<rotate
android:drawable="#drawable/spinner_48_outer_holo"
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="0"
android:toDegrees="1080" />
</item>
<item>
<rotate
android:drawable="#drawable/spinner_48_inner_holo"
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="720"
android:toDegrees="0" />
</item>
</layer-list>
The rotate animation was driven by ProgressBar's onDraw method.
This is a good working example. Param duration is used to animate it.
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="4000"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="720" >
<shape
android:innerRadius="20dp"
android:shape="ring"
android:thickness="4dp"
android:useLevel="false" >
<size
android:height="48dp"
android:width="48dp" />
<gradient
android:centerY="0.5"
android:endColor="#android:color/white"
android:startColor="#00ffffff"
android:type="sweep"
android:useLevel="false" />
</shape>
</rotate>
If you want to rotate drawable forever you can use animated-rotate tag in drawable xml like this.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<animated-rotate android:drawable="#drawable/ic_refresh" android:pivotX="50%" android:pivotY="50%" />
</item>
</selector>

SlidingDrawer semi opened on start

I am working a piece of my app and I was wondering if it's possible to have a Sliding Drawer open partially instead of being fully closed so the user can peak at the text content before clicking the show more button which would be able to show the rest of the text.
Thanks in advance.
I had a similar problem and I ended up modifying SlidingDrawer to be able to show a part of the content when the Drawer is collapsed/closed. With SemiClosedSlidingDrawer you specify how much of the content screen that should be shown in collapsed/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"
>
Then your attrs.xml (in res/values/) also needs to contain:
<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>
, where 'se.smartrefill.app.x' refers to the application package defined in the AndroidManifest.
This specific SlidingDrawer (above) is configured to use horizontal orientation, and a 40dp wide (and fill_parent high) strip of the content view will be shown (to the right) in collapsed/closed mode. In expanded/open mode, this implementation will work just as the standard SlidingDrawer, but in collapsed/closed mode the content screen will never become completely hidden (unless you specify semiClosedContentSize="0dp", which will turn it into a standard SlidingDrawer). This implementation is based on the implementation of SlidingDrawer in Android-4 ("1.6"), but is compatible up to (incl.) Android-14 ("4.0"). This implementation ought to be compatible with future versions of Android as well (almost nothing has changed in SlidingDrawer between API 4 and API 14). This implementation supports both vertical and horizontal orientation.
Try it out!
Regards,
Jacob
I came across a similar problem as you. At the start I only need a (rather narrow) list view in my sliding drawer, so that the user can just have a peak into the content. The drawer should fully open only when an item on the list is selected and some content for that item is displayed in an image view next to the list view.
Therefore my drawer's layout is like that:
<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>
So at the start the image view is gone. In the OnItemClickListener for my list view I control the layout parameters of the drawer:
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
}
};
As you can see I'm using my custom animation for the drawer container so that the nicity of the opening sliding drawer is preserved. Here's the animation class:
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;
}
}
The reason why I am setting new layout parameters is because at the start I'm saving the initial set of parameters (as in the layout file) and apply it back in onDrawerClose:
private OnDrawerCloseListener onDrawerCloseListener = new OnDrawerCloseListener() {
#Override
public void onDrawerClosed() {
imageView.setVisibility(View.GONE);
imageView.setImageDrawable(null);
drawerContainer.setLayoutParams(initialLayoutParams);
}
};
If you want the user to be able to fully open the drawer with the swipe move on the handle, you can apply a similar animation in onTouchListener.
The final remark: my sliding drawer is in a layout because it's included into that layout with so that the drawer is accessible in several places. In general you don't need that layout around your drawer.
Maybe try something like setting the innner content of the of the slidingdrawer be something like
<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>
then set the button ShowMore to toggle the visibility of the linearlayout "More" between View.GONE and View.VISIBLE
**EDIT: Hmm re-reading your question, I'm actually a little confused: the title is "..opened on start", but then you say "open partially". Did you want it to start in the partially opened state? or open partially when the user drags it? My proposal (untested), is to have the sliding drawer wrap its size to the content, and have the content initially start small showing just the button + whatever you want to show outside the "More" inner linear layout, then show that when they click the button.
I recently developed app in which i had requirement as that of required by you.
By googling I found that We have modify source code of original Sliding Drawer I did that and
and whole modified code is with me I had tested and its working fine.
I can send you whole file.Just give me your Email-id.
you also require attrs.xml in your values folder of your project where you want to use this code. attrs.xml code is posted 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>
I hope this will help you.

Categories

Resources