How to create a view similar to the system notification area in android?

I would like to have an idea in my activity that initially remains at the top of the screen, like a small panel, but when you click on it, it should expand downwards, like an area of ​​system notifications.

I did not find standard controls with this behavior. What is the best way to implement this?

+4
source share
4 answers

Use SlidingDrawer . Here is a good tutorial .

+4
source

SlidingDrawer works that way.

+2
source

The problem is that SlidingDrawer cannot be located at the top of the screen - it opens only upwards ( see the corresponding question ). So I implemented a simple control myself using the TranslateAnimation program

class MySlidingDrawer extends LinearLayout { public static final int STATE_OPENED = 0; public static final int STATE_CLOSED = 1; private int m_intState; private LinearLayout m_content; private ImageButton m_handle; public MySlidingDrawer(Context context) { super(context); setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); setOrientation(VERTICAL); setGravity(Gravity.CENTER); m_content = new LinearLayout(context); // add your content here addView(m_content); m_intState = STATE_CLOSED; m_handle = new ImageButton(context); m_handle.setImageResource(R.drawable.icon); m_handle.setOnClickListener(new OnClickListener() { public void onClick(View v) { toggleState(); } }); m_handle.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); addView(m_handle); } private int getContentHeight() { return m_content.getHeight(); } private void toggleState() { int intYStart = 0; int intYEnd = m_intState == STATE_OPENED ? -getContentHeight() : getContentHeight(); Animation a = new TranslateAnimation(0.0f, 0.0f, intYStart, intYEnd); a.setDuration(1000); a.setStartOffset(300); a.setInterpolator(AnimationUtils.loadInterpolator(getContext(), android.R.anim.bounce_interpolator)); startAnimation(a); m_intState = m_intState == STATE_OPENED ? STATE_CLOSED : STATE_OPENED; } protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); offsetTopAndBottom(-getContentHeight()); // content is initially invisible } protected void onAnimationEnd() { super.onAnimationEnd(); int intYOffset = m_intState == STATE_OPENED ? getContentHeight() : -getContentHeight(); offsetTopAndBottom(intYOffset); } } 
+2
source

You can use the code posted in this answer: Android SlidingDrawer on top?

The provided solutions setting the orientation of the Slidingdrawer in xml also just require 1 class and some add-ons in attrs.xml and are stable, since it is obtained from the Androids SlidingDrawer from the SDK. I also discuss why I did not select other popular libraries / solutions found on the Internet / SO.

Quick Essence Link: MultipleOrientationSlidingDrawer (source and example) @gist

0
source

Source: https://habr.com/ru/post/1341842/


All Articles