Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
图标始终可见的Android抽屉_Android_Android Layout - Fatal编程技术网

图标始终可见的Android抽屉

图标始终可见的Android抽屉,android,android-layout,Android,Android Layout,哪个布局组件是构建抽屉菜单的正确组件,该菜单的图标始终可见?我不想使用滑动面板布局,因为主要内容不应该受此影响 1.添加交叉相位滑动面板布局 public class CrossFadeSlidingPaneLayout extends SlidingPaneLayout { private View partialView = null; private View fullView = null; // helper flag pre honeycomb used in vi

哪个布局组件是构建抽屉菜单的正确组件,该菜单的图标始终可见?我不想使用
滑动面板布局
,因为主要内容不应该受此影响


1.添加
交叉相位滑动面板布局

  public class CrossFadeSlidingPaneLayout extends SlidingPaneLayout {
  private View partialView = null;
  private View fullView = null;

  // helper flag pre honeycomb used in visibility and click response handling
  // helps avoid unnecessary layouts
  private boolean wasOpened = false;

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

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

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

  @Override
  protected void onFinishInflate() {
    super.onFinishInflate();

    if (getChildCount() < 1) {
      return;
    }

    View panel = getChildAt(0);
    if (!(panel instanceof ViewGroup)) {
      return;
    }

    ViewGroup viewGroup = (ViewGroup) panel;
    if (viewGroup.getChildCount() != 2) {
      return;
    }
    fullView = viewGroup.getChildAt(0);
    partialView = viewGroup.getChildAt(1);

    super.setPanelSlideListener(crossFadeListener);
  }

  @Override
  public void setPanelSlideListener(final PanelSlideListener listener) {
    if (listener == null) {
      super.setPanelSlideListener(crossFadeListener);
      return;
    }

    super.setPanelSlideListener(new PanelSlideListener() {
      @Override
      public void onPanelSlide(View panel, float slideOffset) {
        crossFadeListener.onPanelSlide(panel, slideOffset);
        listener.onPanelSlide(panel, slideOffset);
      }

      @Override
      public void onPanelOpened(View panel) {
        listener.onPanelOpened(panel);
      }

      @Override
      public void onPanelClosed(View panel) {
        listener.onPanelClosed(panel);
      }
    });
  }

  @Override
  protected void onLayout(boolean changed, int l, int t, int r, int b) {
    super.onLayout(changed, l, t, r, b);

    if (partialView != null) {
      if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        // "changed" means that views were added or removed
        // we need to move the partial view out of the way in any case (if it's supposed to of course)
        updatePartialViewVisibilityPreHoneycomb(isOpen());
      } else {
        partialView.setVisibility(isOpen() ? View.GONE : VISIBLE);
      }
    }
  }

  private SimplePanelSlideListener crossFadeListener = new SimplePanelSlideListener() {
    @Override
    public void onPanelSlide(View panel, float slideOffset) {
      super.onPanelSlide(panel, slideOffset);
      if (partialView == null || fullView == null) {
        return;
      }

      if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        if (slideOffset == 1 && !wasOpened) {
          // the layout was just opened, move the partial view off screen
          updatePartialViewVisibilityPreHoneycomb(true);
          wasOpened = true;
        } else if (slideOffset < 1 && wasOpened) {
          // the layout just started to close, move the partial view back, so it can be shown animating
          updatePartialViewVisibilityPreHoneycomb(false);
          wasOpened = false;
        }
      } else {
        partialView.setVisibility(isOpen() ? View.GONE : VISIBLE);
      }

      ViewHelper.setAlpha(partialView, 1 - slideOffset);
      ViewHelper.setAlpha(fullView, slideOffset);
    }
  };

  private void updatePartialViewVisibilityPreHoneycomb(boolean slidingPaneOpened) {
    // below API 11 the top view must be moved so it does not consume clicks intended for the bottom view
    // this applies curiously even when setting its visibility to GONE
    // this might be due to platform limitations or it may have been introduced by NineOldAndroids library
    if (slidingPaneOpened) {
      partialView.layout(-partialView.getWidth(), 0, 0, partialView.getHeight());
    } else {
      partialView.layout(0, 0, partialView.getWidth(), partialView.getHeight());
    }
  }
}
公共类CrossFadeSlidingPaneLayout扩展了SlidingPaneLayout{
私有视图partialView=null;
私有视图fullView=null;
//在可见性中使用的辅助标志pre-honeycomb,并单击响应处理
//有助于避免不必要的布局
私有布尔值waspopened=false;
公共交叉时尚LidingPanel布局(上下文){
超级(上下文);
}
public CrossFadesLidingPanel布局(上下文、属性集属性){
超级(上下文,attrs);
}
public CrossFadesLidingPanel布局(上下文、属性集属性、int-defStyle){
超级(上下文、属性、定义样式);
}
@凌驾
充气时受保护的空隙(){
超级充气();
if(getChildCount()<1){
返回;
}
视图面板=getChildAt(0);
如果(!(视图组的面板实例)){
返回;
}
ViewGroup ViewGroup=(ViewGroup)面板;
如果(viewGroup.getChildCount()!=2){
返回;
}
fullView=viewGroup.getChildAt(0);
partialView=viewGroup.getChildAt(1);
super.setPanelSlideListener(crossfadellistener);
}
@凌驾
public void setPanelSlideListener(最终PanelSlideListener侦听器){
if(侦听器==null){
super.setPanelSlideListener(crossfadellistener);
返回;
}
super.setPanelSlideListener(新的PanelSlideListener(){
@凌驾
公共空心面板幻灯片(视图面板、浮动幻灯片偏移){
crossFadeListener.onPanelSlide(面板,滑块偏移);
listener.onPanelSlide(面板,slideOffset);
}
@凌驾
打开的公用面板(视图面板){
listener.onPanelOpen(面板);
}
@凌驾
公共面板已关闭(视图面板){
listener.onPanelClosed(面板);
}
});
}
@凌驾
仅受保护的void布局(布尔值已更改、int l、int t、int r、int b){
超级在线布局(更改,l,t,r,b);
if(partialView!=null){
if(Build.VERSION.SDK\u INT
2.活动布局

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

    <FrameLayout
        android:layout_width="@dimen/side_pane_width"
        android:layout_height="match_parent"
        android:background="@color/purple">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:gravity="center_horizontal"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:orientation="horizontal">

                <ImageView
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:layout_marginLeft="7dp"
                    android:background="@drawable/ic_launcher" />

                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:text="Your Screen" />
            </LinearLayout>


            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:orientation="horizontal">

                <ImageView
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:layout_marginLeft="7dp"
                    android:background="@drawable/ic_launcher" />

                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:text="Your Screen" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:orientation="horizontal">

                <ImageView
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:layout_marginLeft="7dp"
                    android:background="@drawable/ic_launcher" />

                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:text="Your Screen" />
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:layout_width="55dp"
            android:layout_height="fill_parent"
            android:gravity="center_horizontal"
            android:orientation="vertical">

            <ImageView
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:background="@drawable/ic_launcher" />

            <ImageView
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:background="@drawable/ic_launcher" />

            <ImageView
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:background="@drawable/ic_launcher" />
        </LinearLayout>

    </FrameLayout>

    <TextView
        android:layout_width="@dimen/main_pane_width"
        android:layout_height="match_parent"
        android:layout_marginLeft="@dimen/partial_pane_width"
        android:layout_weight="1"
        android:background="@color/light_blue"
        android:text="@string/pane_2" />
</com.xxx.CrossFadeSlidingPaneLayout>

其“立即完成”始终菜单将可见:)


归因于原始项目:

如果你能更清楚地解释你的问题,这会有所帮助……在这种布局下,图标是可见的,所以这是一个好的开始。但是,它不允许展开菜单。还是我遗漏了什么?@MarkusPalme用展开菜单检查更新的答案