安卓音乐播放器--侧边栏

侧边栏学习

参考资料:http://www.chinatarena.com/Html/adpeixun/201307/5251.html

还有一个参考的代码 最后自己的理解是 在scrollView中添加两个水平的视图 

		musicListLayout.findViewById(R.id.btnMusicListSlide).setOnClickListener(new MusicListActivity.ClickListenerForScrolling(scrollView, menu));
		final View[] children=new View[]{menuLayout,musicListLayout};
		int scrollToViewIdx=0;
		scrollView.initViews(children, scrollToViewIdx, new MusicListActivity.SizeCallbackForMenu(musicListLayout.findViewById(R.id.btnMusicListSlide))
之前使用一个透明的TextView替代menuLayout 之前的menuLayout如下:




    
    
        

采用帧布局 在菜单滑出时透明层将app“挤”过去一些 由于是帧布局 其上是透明层 于是就把底下的menu显示出来(网上下载的demo)后想改成右边的菜单栏 无法实现 每次都会显示成菜单的后半段 如图

安卓音乐播放器--侧边栏_第1张图片

之前没太明白为什么 后来想 这样透明层是推开了 但是底下的还是没变 所以会这样吧 于是后来不用透明层 直接用menuLayout 作为children 但是会报错 

安卓音乐播放器--侧边栏_第2张图片

意思是它已经有了一个父节点 然后将menuLayout中的MyHorizontalScrollView单独写成一个xml 然后在setContentView时设置为MyHorizontalScrollView 在MyHorizontalScrollView代码中更改了onGlobalLayout中添加children的顺序 于是就能从右边滑出 至于为什么 我可以说是一种直觉么。。 哈哈 下面贴上MyHorizontalScrollView 的代码(其实百度一下有超多的)

/*
 * #%L
 * SlidingMenuDemo
 * $Id:$
 * $HeadURL:$
 * %%
 * Copyright (C) 2012 Paul Grime
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */
package com.vanhon.mediaplayer2.view;

import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.HorizontalScrollView;

/**
 * A HorizontalScrollView (HSV) implementation that disallows touch events (so no scrolling can be done by the user).
 * 
 * This HSV MUST contain a single ViewGroup as its only child, and this ViewGroup will be used to display the children Views
 * passed in to the initViews() method.
 */
public class MyHorizontalScrollView extends HorizontalScrollView {
    public MyHorizontalScrollView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context);
    }

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

    public MyHorizontalScrollView(Context context) {
        super(context);
        init(context);
    }

    void init(Context context) {
        // remove the fading as the HSV looks better without it
        setHorizontalFadingEdgeEnabled(false);
        setVerticalFadingEdgeEnabled(false);
    }

    /**
     * @param children
     *            The child Views to add to parent.
     * @param scrollToViewIdx
     *            The index of the View to scroll to after initialisation.
     * @param sizeCallback
     *            A SizeCallback to interact with the HSV.
     */
    public void initViews(View[] children, int scrollToViewIdx, SizeCallback sizeCallback) {
        // A ViewGroup MUST be the only child of the HSV
        ViewGroup parent = (ViewGroup) getChildAt(0);

        // Add all the children, but add them invisible so that the layouts are calculated, but you can't see the Views
        for (int i = 0; i 安卓音乐播放器--侧边栏_第3张图片

你可能感兴趣的:(安卓音乐播放器--侧边栏)