最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android實(shí)現(xiàn)上下菜單雙向滑動(dòng)效果

 更新時(shí)間:2018年01月24日 11:56:13   作者:hahashui123  
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)上下菜單雙向滑動(dòng)效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

這是研究了網(wǎng)上大神雙向左右滑動(dòng)后實(shí)現(xiàn)的上下雙向滑動(dòng)特效,有興趣的朋友可以看下面代碼,注釋很詳細(xì),原理就是根據(jù)手指滑動(dòng)的方向,來將上下兩個(gè)布局進(jìn)行顯示與隱藏。主要用了onTouch方法,獲取滑動(dòng)的距離進(jìn)行偏移。

import android.content.Context; 
import android.os.AsyncTask; 
import android.util.AttributeSet; 
import android.view.MotionEvent; 
import android.view.VelocityTracker; 
import android.view.View; 
import android.view.ViewConfiguration; 
import android.view.WindowManager; 
import android.view.View.OnTouchListener; 
import android.widget.RelativeLayout; 
 
public class UpAndDownSlidinglayout extends RelativeLayout implements OnTouchListener{ 
  /** 
   * 滾動(dòng)顯示和隱藏上側(cè)布局時(shí),手指滑動(dòng)需要達(dá)到的速度。 
   */ 
  public static final int SNAP_VELOCITY = 200; 
 
  /** 
   * 滑動(dòng)狀態(tài)的一種,表示未進(jìn)行任何滑動(dòng)。 
   */ 
  public static final int DO_NOTHING = 0; 
  /** 
   * 滑動(dòng)狀態(tài)的一種,表示正在滑出上側(cè)菜單。 
   */ 
  public static final int SHOW_UP_MENU = 1; 
 
  /** 
   * 滑動(dòng)狀態(tài)的一種,表示正在滑出下側(cè)菜單。 
   */ 
  public static final int SHOW_DOWN_MENU = 2; 
 
  /** 
   * 滑動(dòng)狀態(tài)的一種,表示正在隱藏上側(cè)菜單。 
   */ 
  public static final int HIDE_UP_MENU = 3; 
 
  /** 
   * 滑動(dòng)狀態(tài)的一種,表示正在隱藏下側(cè)菜單。 
   */ 
  public static final int HIDE_DOWN_MENU = 4; 
 
  /** 
   * 記錄當(dāng)前的滑動(dòng)狀態(tài) 
   */ 
  private int slideState; 
 
  /** 
   * 屏幕寬度值。 
   */ 
  private int screenWidth; 
  private int screenHeight; 
 
  /** 
   * 在被判定為滾動(dòng)之前用戶手指可以移動(dòng)的最大值。 
   */ 
  private int touchSlop; 
 
  /** 
   * 記錄手指按下時(shí)的橫坐標(biāo)。 
   */ 
  private float xDown; 
 
  /** 
   * 記錄手指按下時(shí)的縱坐標(biāo)。 
   */ 
  private float yDown; 
 
  /** 
   * 記錄手指移動(dòng)時(shí)的橫坐標(biāo)。 
   */ 
  private float xMove; 
 
  /** 
   * 記錄手指移動(dòng)時(shí)的縱坐標(biāo)。 
   */ 
  private float yMove; 
 
  /** 
   * 記錄手機(jī)抬起時(shí)的縱坐標(biāo)。 
   */ 
  private float yUp; 
  /** 
   * 上側(cè)菜單當(dāng)前是顯示還是隱藏。只有完全顯示或隱藏時(shí)才會(huì)更改此值,滑動(dòng)過程中此值無效。 
   */ 
  private boolean isUpMenuVisible; 
 
  /** 
   * 下側(cè)菜單當(dāng)前是顯示還是隱藏。只有完全顯示或隱藏時(shí)才會(huì)更改此值,滑動(dòng)過程中此值無效。 
   */ 
  private boolean isDownMenuVisible; 
 
  /** 
   * 是否正在滑動(dòng)。 
   */ 
  private boolean isSliding; 
 
  /** 
   * 上側(cè)菜單布局對象。 
   */ 
  private View upMenuLayout; 
 
  /** 
   * 下側(cè)菜單布局對象。 
   */ 
  private View downMenuLayout; 
 
  /** 
   * 內(nèi)容布局對象。 
   */ 
  private View contentLayout; 
 
  /** 
   * 用于監(jiān)聽滑動(dòng)事件的View。 
   */ 
  private View mBindView; 
 
  /** 
   * 上側(cè)菜單布局的參數(shù)。 
   */ 
  private MarginLayoutParams upMenuLayoutParams; 
 
  /** 
   * 下側(cè)菜單布局的參數(shù)。 
   */ 
  private MarginLayoutParams downMenuLayoutParams; 
 
  /** 
   * 內(nèi)容布局的參數(shù)。 
   */ 
  private RelativeLayout.LayoutParams contentLayoutParams; 
 
  /** 
   * 用于計(jì)算手指滑動(dòng)的速度。 
   */ 
  private VelocityTracker mVelocityTracker; 
   
  public UpAndDownSlidinglayout(Context context, AttributeSet attrs) { 
    super(context, attrs); 
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 
    screenWidth = wm.getDefaultDisplay().getWidth(); 
    screenHeight = wm.getDefaultDisplay().getHeight(); 
    touchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); 
  } 
  /** 
   * 綁定監(jiān)聽滑動(dòng)事件的View。 
   * 
   * @param bindView 
   *      需要綁定的View對象。 
   */ 
  public void setScrollEvent(View bindView) { 
    mBindView = bindView; 
    mBindView.setOnTouchListener(this); 
  } 
  @Override 
  public boolean onTouch(View v, MotionEvent event) { 
    // TODO Auto-generated method stub 
    createVelocityTracker(event); 
    switch (event.getAction()) { 
    case MotionEvent.ACTION_DOWN: 
      // 手指按下時(shí),記錄按下時(shí)的坐標(biāo) 
      xDown = event.getRawX(); 
      yDown = event.getRawY(); 
      // 將滑動(dòng)狀態(tài)初始化為DO_NOTHING 
      slideState = DO_NOTHING; 
      break; 
    case MotionEvent.ACTION_MOVE: 
      xMove = event.getRawX(); 
      yMove = event.getRawY(); 
      int moveDistanceX = (int) (xMove - xDown); 
      int moveDistanceY = (int) (yMove - yDown); 
      // 檢查當(dāng)前的滑動(dòng)狀態(tài) 
      checkSlideState(moveDistanceX, moveDistanceY); 
      switch (slideState) { 
      case SHOW_UP_MENU: 
        contentLayoutParams.bottomMargin = -moveDistanceY; 
        checkUpMenuBorder(); 
        contentLayout.setLayoutParams(contentLayoutParams); 
        break; 
      case HIDE_UP_MENU: 
        contentLayoutParams.bottomMargin = -upMenuLayoutParams.height - moveDistanceY; 
        checkUpMenuBorder(); 
        contentLayout.setLayoutParams(contentLayoutParams); 
      case SHOW_DOWN_MENU: 
        contentLayoutParams.topMargin = moveDistanceY; 
        checkDownMenuBorder(); 
        contentLayout.setLayoutParams(contentLayoutParams); 
        break; 
      case HIDE_DOWN_MENU: 
        contentLayoutParams.topMargin = -downMenuLayoutParams.height + moveDistanceY; 
        checkDownMenuBorder(); 
        contentLayout.setLayoutParams(contentLayoutParams); 
      default: 
        break; 
      } 
       
      break; 
    case MotionEvent.ACTION_UP: 
      yUp = event.getRawY(); 
      int upDistanceY = (int) (yUp - yDown); 
      if (isSliding) { 
        // 手指抬起時(shí),進(jìn)行判斷當(dāng)前手勢的意圖 
        switch (slideState) { 
        case SHOW_UP_MENU: 
          if (shouldScrollToUpMenu()) { 
            scrollToUpMenu(); 
          } else { 
            scrollToContentFromUpMenu(); 
          } 
          break; 
        case HIDE_UP_MENU: 
          if (shouldScrollToContentFromUpMenu()) { 
            scrollToContentFromUpMenu(); 
          } else { 
            scrollToUpMenu(); 
          } 
          break; 
        case SHOW_DOWN_MENU: 
          if (shouldScrollToDownMenu()) { 
            scrollToDownMenu(); 
          } else { 
            scrollToContentFromDownMenu(); 
          } 
          break; 
        case HIDE_DOWN_MENU: 
          if (shouldScrollToContentFromDownMenu()) { 
            scrollToContentFromDownMenu(); 
          } else { 
            scrollToDownMenu(); 
          } 
          break; 
        default: 
          break; 
        } 
      }else if (upDistanceY < touchSlop && isUpMenuVisible) { 
        // 當(dāng)上側(cè)菜單顯示時(shí),如果用戶點(diǎn)擊一下內(nèi)容部分,則直接滾動(dòng)到內(nèi)容界面 
        scrollToContentFromUpMenu(); 
      } else if (upDistanceY < touchSlop && isDownMenuVisible) { 
        // 當(dāng)下側(cè)菜單顯示時(shí),如果用戶點(diǎn)擊一下內(nèi)容部分,則直接滾動(dòng)到內(nèi)容界面 
        scrollToContentFromDownMenu(); 
      } 
      recycleVelocityTracker(); 
      break; 
    } 
    return true; 
  } 
   
  /** 
   * 創(chuàng)建VelocityTracker對象,并將觸摸事件加入到VelocityTracker當(dāng)中。 
   * 
   * @param event 
   *       
   */ 
  private void createVelocityTracker(MotionEvent event) { 
    if (mVelocityTracker == null) { 
      mVelocityTracker = VelocityTracker.obtain(); 
    } 
    mVelocityTracker.addMovement(event); 
  } 
   
  /** 
   * 根據(jù)手指移動(dòng)的距離,判斷當(dāng)前用戶的滑動(dòng)意圖,然后給slideState賦值成相應(yīng)的滑動(dòng)狀態(tài)值。 
   * 
   * @param moveDistanceX 
   *      橫向移動(dòng)的距離 
   * @param moveDistanceY 
   *      縱向移動(dòng)的距離 
   */ 
  private void checkSlideState(int moveDistanceX, int moveDistanceY) { 
    if(isUpMenuVisible){ 
      if (!isSliding && Math.abs(moveDistanceY) >= touchSlop && moveDistanceY < 0) { 
        isSliding = true; 
        slideState = HIDE_UP_MENU; 
      } 
    }else if(isDownMenuVisible){ 
      if (!isSliding && Math.abs(moveDistanceY) >= touchSlop && moveDistanceY > 0) { 
        isSliding = true; 
        slideState = HIDE_DOWN_MENU; 
      } 
    }else{ 
      if (!isSliding && Math.abs(moveDistanceY) >= touchSlop && moveDistanceY > 0 
          && Math.abs(moveDistanceX) < touchSlop) { 
        isSliding = true; 
        slideState = SHOW_UP_MENU; 
        contentLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0); 
        contentLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 
        contentLayout.setLayoutParams(contentLayoutParams); 
        // 如果用戶想要滑動(dòng)上側(cè)菜單,將上側(cè)菜單顯示,下側(cè)菜單隱藏 
        upMenuLayout.setVisibility(View.VISIBLE); 
        downMenuLayout.setVisibility(View.GONE); 
      }else if(!isSliding && Math.abs(moveDistanceY) >= touchSlop && moveDistanceY < 0 
          && Math.abs(moveDistanceX) < touchSlop){ 
        isSliding = true; 
        slideState = SHOW_DOWN_MENU; 
        contentLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 0); 
        contentLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); 
        contentLayout.setLayoutParams(contentLayoutParams); 
        // 如果用戶想要滑動(dòng)下側(cè)菜單,將下側(cè)菜單顯示,上側(cè)菜單隱藏 
        upMenuLayout.setVisibility(View.GONE); 
        downMenuLayout.setVisibility(View.VISIBLE); 
      } 
    } 
  } 
   
  /** 
   * 在滑動(dòng)過程中檢查上側(cè)菜單的邊界值,防止綁定布局滑出屏幕。 
   */ 
  private void checkUpMenuBorder() { 
    if (contentLayoutParams.bottomMargin > 0) { 
      contentLayoutParams.bottomMargin = 0; 
    } else if (contentLayoutParams.bottomMargin < -upMenuLayoutParams.height) { 
      contentLayoutParams.bottomMargin = -upMenuLayoutParams.height; 
    } 
  } 
  /** 
   * 在滑動(dòng)過程中檢查下側(cè)菜單的邊界值,防止綁定布局滑出屏幕。 
   */ 
  private void checkDownMenuBorder() { 
    if (contentLayoutParams.topMargin > 0) { 
      contentLayoutParams.topMargin = 0; 
    } else if (contentLayoutParams.topMargin < -downMenuLayoutParams.height) { 
      contentLayoutParams.topMargin = -downMenuLayoutParams.height; 
    } 
  } 
  /** 
   * 判斷是否應(yīng)該滾動(dòng)將上側(cè)菜單展示出來。如果手指移動(dòng)距離大于上側(cè)菜單寬度的1/2,或者手指移動(dòng)速度大于SNAP_VELOCITY, 
   * 就認(rèn)為應(yīng)該滾動(dòng)將上側(cè)菜單展示出來。 
   * 
   * @return 如果應(yīng)該將上側(cè)菜單展示出來返回true,否則返回false。 
   */ 
  private boolean shouldScrollToUpMenu() { 
    return yUp - yDown > upMenuLayoutParams.height / 2 || getScrollVelocity() > SNAP_VELOCITY; 
  } 
 
  /** 
   * 判斷是否應(yīng)該滾動(dòng)將下側(cè)菜單展示出來。如果手指移動(dòng)距離大于下側(cè)菜單寬度的1/2,或者手指移動(dòng)速度大于SNAP_VELOCITY, 
   * 就認(rèn)為應(yīng)該滾動(dòng)將下側(cè)菜單展示出來。 
   * 
   * @return 如果應(yīng)該將下側(cè)菜單展示出來返回true,否則返回false。 
   */ 
  private boolean shouldScrollToDownMenu() { 
    return yDown - yUp > downMenuLayoutParams.height / 2 || getScrollVelocity() > SNAP_VELOCITY; 
  } 
 
  /** 
   * 判斷是否應(yīng)該從上側(cè)菜單滾動(dòng)到內(nèi)容布局,如果手指移動(dòng)距離大于上側(cè)菜單寬度的1/2,或者手指移動(dòng)速度大于SNAP_VELOCITY, 
   * 就認(rèn)為應(yīng)該從上側(cè)菜單滾動(dòng)到內(nèi)容布局。 
   * 
   * @return 如果應(yīng)該從上側(cè)菜單滾動(dòng)到內(nèi)容布局返回true,否則返回false。 
   */ 
  private boolean shouldScrollToContentFromUpMenu() { 
    return yDown - yUp > upMenuLayoutParams.height / 2 || getScrollVelocity() > SNAP_VELOCITY; 
  } 
 
  /** 
   * 判斷是否應(yīng)該從下側(cè)菜單滾動(dòng)到內(nèi)容布局,如果手指移動(dòng)距離大于下側(cè)菜單寬度的1/2,或者手指移動(dòng)速度大于SNAP_VELOCITY, 
   * 就認(rèn)為應(yīng)該從下側(cè)菜單滾動(dòng)到內(nèi)容布局。 
   * 
   * @return 如果應(yīng)該從下側(cè)菜單滾動(dòng)到內(nèi)容布局返回true,否則返回false。 
   */ 
  private boolean shouldScrollToContentFromDownMenu() { 
    return yUp - yDown > downMenuLayoutParams.height / 2 || getScrollVelocity() > SNAP_VELOCITY; 
  } 
  /** 
   * 獲取手指在綁定布局上的滑動(dòng)速度。 
   * 
   * @return 滑動(dòng)速度,以每秒鐘移動(dòng)了多少像素值為單位。 
   */ 
  private int getScrollVelocity() { 
    mVelocityTracker.computeCurrentVelocity(1000); 
    int velocity = (int) mVelocityTracker.getXVelocity(); 
    return Math.abs(velocity); 
  } 
   
  class UpMenuScrollTask extends AsyncTask<Integer, Integer, Integer> { 
 
    @Override 
    protected Integer doInBackground(Integer... speed) { 
      int bottomMargin = contentLayoutParams.bottomMargin; 
      // 根據(jù)傳入的速度來滾動(dòng)界面,當(dāng)滾動(dòng)到達(dá)邊界值時(shí),跳出循環(huán)。 
      while (true) { 
        bottomMargin = bottomMargin + speed[0]; 
        if (bottomMargin < -upMenuLayoutParams.height) { 
          bottomMargin = -upMenuLayoutParams.height; 
          break; 
        } 
        if (bottomMargin > 0) { 
          bottomMargin = 0; 
          break; 
        } 
        publishProgress(bottomMargin); 
        // 為了要有滾動(dòng)效果產(chǎn)生,每次循環(huán)使線程睡眠一段時(shí)間,這樣肉眼才能夠看到滾動(dòng)動(dòng)畫。 
        sleep(15); 
      } 
      if (speed[0] > 0) { 
        isUpMenuVisible = false; 
      } else { 
        isUpMenuVisible = true; 
      } 
      isSliding = false; 
      return bottomMargin; 
    } 
 
    @Override 
    protected void onProgressUpdate(Integer... bottomMargin) { 
      contentLayoutParams.bottomMargin = bottomMargin[0]; 
      contentLayout.setLayoutParams(contentLayoutParams); 
      unFocusBindView(); 
    } 
 
    @Override 
    protected void onPostExecute(Integer bottomMargin) { 
      contentLayoutParams.bottomMargin = bottomMargin; 
      contentLayout.setLayoutParams(contentLayoutParams); 
    } 
  } 
   
  class DownMenuScrollTask extends AsyncTask<Integer, Integer, Integer> { 
 
    @Override 
    protected Integer doInBackground(Integer... speed) { 
      int topMargin = contentLayoutParams.topMargin; 
      // 根據(jù)傳入的速度來滾動(dòng)界面,當(dāng)滾動(dòng)到達(dá)邊界值時(shí),跳出循環(huán)。 
      while (true) { 
        topMargin = topMargin + speed[0]; 
        if (topMargin < -downMenuLayoutParams.height) { 
          topMargin = -downMenuLayoutParams.height; 
          break; 
        } 
        if (topMargin > 0) { 
          topMargin = 0; 
          break; 
        } 
        publishProgress(topMargin); 
        // 為了要有滾動(dòng)效果產(chǎn)生,每次循環(huán)使線程睡眠一段時(shí)間,這樣肉眼才能夠看到滾動(dòng)動(dòng)畫。 
        sleep(15); 
      } 
      if (speed[0] > 0) { 
        isDownMenuVisible = false; 
      } else { 
        isDownMenuVisible = true; 
      } 
      isSliding = false; 
      return topMargin; 
    } 
 
    @Override 
    protected void onProgressUpdate(Integer... topMargin) { 
      contentLayoutParams.topMargin = topMargin[0]; 
      contentLayout.setLayoutParams(contentLayoutParams); 
      unFocusBindView(); 
    } 
 
    @Override 
    protected void onPostExecute(Integer topMargin) { 
      contentLayoutParams.topMargin = topMargin; 
      contentLayout.setLayoutParams(contentLayoutParams); 
    } 
  } 
  /** 
   * 使當(dāng)前線程睡眠指定的毫秒數(shù)。 
   * 
   * @param millis 
   *      指定當(dāng)前線程睡眠多久,以毫秒為單位 
   */ 
  private void sleep(long millis) { 
    try { 
      Thread.sleep(millis); 
    } catch (InterruptedException e) { 
      e.printStackTrace(); 
    } 
  } 
  /** 
   * 使用可以獲得焦點(diǎn)的控件在滑動(dòng)的時(shí)候失去焦點(diǎn)。 
   */ 
  private void unFocusBindView() { 
    if (mBindView != null) { 
      mBindView.setPressed(false); 
      mBindView.setFocusable(false); 
      mBindView.setFocusableInTouchMode(false); 
    } 
  } 
   
  /** 
   * 將界面滾動(dòng)到上側(cè)菜單界面,滾動(dòng)速度設(shè)定為-30. 
   */ 
  public void scrollToUpMenu() { 
    new UpMenuScrollTask().execute(-30); 
  } 
 
  /** 
   * 將界面滾動(dòng)到下側(cè)菜單界面,滾動(dòng)速度設(shè)定為-30. 
   */ 
  public void scrollToDownMenu() { 
    new DownMenuScrollTask().execute(-30); 
  } 
 
  /** 
   * 將界面從上側(cè)菜單滾動(dòng)到內(nèi)容界面,滾動(dòng)速度設(shè)定為30. 
   */ 
  public void scrollToContentFromUpMenu() { 
    new UpMenuScrollTask().execute(30); 
  } 
 
  /** 
   * 將界面從下側(cè)菜單滾動(dòng)到內(nèi)容界面,滾動(dòng)速度設(shè)定為30. 
   */ 
  public void scrollToContentFromDownMenu() { 
    new DownMenuScrollTask().execute(30); 
  } 
 
  /** 
   * 上側(cè)菜單是否完全顯示出來,滑動(dòng)過程中此值無效。 
   * 
   * @return 上側(cè)菜單完全顯示返回true,否則返回false。 
   */ 
  public boolean isUpLayoutVisible() { 
    return isUpMenuVisible; 
  } 
 
  /** 
   * 下側(cè)菜單是否完全顯示出來,滑動(dòng)過程中此值無效。 
   * 
   * @return 下側(cè)菜單完全顯示返回true,否則返回false。 
   */ 
  public boolean isDownLayoutVisible() { 
    return isDownMenuVisible; 
  } 
 
  /** 
   * 在onLayout中重新設(shè)定上側(cè)菜單、下側(cè)菜單、以及內(nèi)容布局的參數(shù)。 
   */ 
  @Override 
  protected void onLayout(boolean changed, int l, int t, int r, int b) { 
    super.onLayout(changed, l, t, r, b); 
    if (changed) { 
      // 獲取上側(cè)菜單布局對象 
      upMenuLayout = getChildAt(0); 
      upMenuLayoutParams = (MarginLayoutParams) upMenuLayout.getLayoutParams(); 
      // 獲取下側(cè)菜單布局對象 
      downMenuLayout = getChildAt(1); 
      downMenuLayoutParams = (MarginLayoutParams) downMenuLayout.getLayoutParams(); 
      // 獲取內(nèi)容布局對象 
      contentLayout = getChildAt(2); 
      contentLayoutParams = (RelativeLayout.LayoutParams) contentLayout.getLayoutParams(); 
      contentLayoutParams.height = screenHeight; 
      contentLayout.setLayoutParams(contentLayoutParams); 
    } 
  } 
  /** 
   * 回收VelocityTracker對象。 
   */ 
  private void recycleVelocityTracker() { 
    mVelocityTracker.recycle(); 
    mVelocityTracker = null; 
  } 
} 

下面是使用實(shí)例:

import android.os.Bundle; 
import android.widget.ArrayAdapter; 
import android.widget.LinearLayout; 
import android.widget.ListView; 
import android.app.Activity; 
 
/** 
 * 滑動(dòng)菜單Demo主Activity 
 * 
 * @author guolin 
 */ 
public class MainActivity2 extends Activity { 
 
  /** 
   * 雙向滑動(dòng)菜單布局 
   */ 
  private UpAndDownSlidinglayout updownSldingLayout; 
 
  /** 
   * 在內(nèi)容布局上顯示的ListView 
   */ 
  private ListView contentList; 
  private LinearLayout ll; 
  /** 
   * ListView的適配器 
   */ 
  private ArrayAdapter<String> contentListAdapter; 
 
  /** 
   * 用于填充contentListAdapter的數(shù)據(jù)源。 
   */ 
  private String[] contentItems = { "Content Item 1", "Content Item 2", "Content Item 3", 
      "Content Item 4", "Content Item 5", "Content Item 6", "Content Item 7", 
      "Content Item 8", "Content Item 9", "Content Item 10", "Content Item 11", 
      "Content Item 12", "Content Item 13", "Content Item 14", "Content Item 15", 
      "Content Item 16" }; 
 
  @Override 
  protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main2); 
    ll = (LinearLayout) findViewById(R.id.content); 
    updownSldingLayout = (UpAndDownSlidinglayout) findViewById(R.id.updown_sliding_layout); 
    contentList = (ListView) findViewById(R.id.contentList); 
    contentListAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, 
        contentItems); 
    contentList.setAdapter(contentListAdapter); 
    updownSldingLayout.setScrollEvent(ll); 
  } 
 
} 

布局文件:

<com.example.UpAndDownSlidinglayout xmlns:android="http://schemas.android.com/apk/res/android" 
  xmlns:tools="http://schemas.android.com/tools" 
  android:id="@+id/updown_sliding_layout" 
  android:layout_width="fill_parent" 
  android:layout_height="fill_parent" > 
 
  <RelativeLayout 
    android:id="@+id/up_menu" 
    android:layout_width="fill_parent" 
    android:layout_height="300dp" 
    android:layout_alignParentTop="true" 
    android:background="#00ccff" 
    android:visibility="invisible" > 
 
    <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:text="This is up menu" 
      android:textColor="#000000" 
      android:textSize="28sp" /> 
  </RelativeLayout> 
 
  <RelativeLayout 
    android:id="@+id/down_menu" 
    android:layout_width="fill_parent" 
    android:layout_height="300dp" 
    android:layout_alignParentBottom="true" 
    android:background="#00ffcc" 
    android:visibility="invisible" > 
 
    <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:text="This is down menu" 
      android:textColor="#000000" 
      android:textSize="28sp" /> 
  </RelativeLayout> 
 
  <LinearLayout 
    android:id="@+id/content" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:gravity="center" 
    android:background="#e9e9e9" > 
 
    <ListView 
      android:id="@+id/contentList" 
      android:layout_width="fill_parent" 
      android:layout_height="500dp" 
      android:scrollbars="none" 
      android:cacheColorHint="#00000000" > 
    </ListView> 
  </LinearLayout> 
 
</com.example.UpAndDownSlidinglayout> 

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android實(shí)現(xiàn)生成二維碼并保存到相冊

    Android實(shí)現(xiàn)生成二維碼并保存到相冊

    這篇文章主要介紹了如何利用Android實(shí)現(xiàn)二維碼的生成,并且保存到本地相冊。文中的示例代碼講解詳細(xì),感興趣的小伙伴快跟隨小編學(xué)習(xí)一下
    2022-04-04
  • Android?Studio實(shí)現(xiàn)簡單頁面跳轉(zhuǎn)的詳細(xì)教程

    Android?Studio實(shí)現(xiàn)簡單頁面跳轉(zhuǎn)的詳細(xì)教程

    這篇文章主要給大家介紹了關(guān)于Android?Studio實(shí)現(xiàn)簡單頁面跳轉(zhuǎn)的詳細(xì)教程,文中通過圖文介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用Android?Studio具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2023-01-01
  • Android框架Volley使用之Json請求實(shí)現(xiàn)

    Android框架Volley使用之Json請求實(shí)現(xiàn)

    這篇文章主要介紹了Android框架Volley使用之Json請求實(shí)現(xiàn),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下
    2019-05-05
  • Android應(yīng)用實(shí)現(xiàn)安裝后自啟動(dòng)的方法

    Android應(yīng)用實(shí)現(xiàn)安裝后自啟動(dòng)的方法

    今天小編就為大家分享一篇Android應(yīng)用實(shí)現(xiàn)安裝后自啟動(dòng)的方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-08-08
  • Android仿微信主界面的實(shí)現(xiàn)方法

    Android仿微信主界面的實(shí)現(xiàn)方法

    這篇文章主要為大家詳細(xì)介紹了Android仿微信主界面的實(shí)現(xiàn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-04-04
  • android 多線程技術(shù)應(yīng)用

    android 多線程技術(shù)應(yīng)用

    能夠在屏幕上“實(shí)時(shí)地顯示”時(shí)間的流逝,單線程程序是無法實(shí)現(xiàn)的,必須要多線程程序才可以實(shí)現(xiàn),即便有些計(jì)算機(jī)語言可以通過封裝好的類實(shí)現(xiàn)這一功能,但從本質(zhì)上講這些封裝好的類就是封裝了一個(gè)線程,具體祥看本文
    2012-12-12
  • Android10 啟動(dòng)Zygote源碼解析

    Android10 啟動(dòng)Zygote源碼解析

    這篇文章主要為大家介紹了Android 10 啟動(dòng)分析之Zygote篇,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-10-10
  • Android自定義RadioGroupX實(shí)現(xiàn)多行多列布局

    Android自定義RadioGroupX實(shí)現(xiàn)多行多列布局

    這篇文章主要為大家詳細(xì)介紹了Android自定義RadioGroupX實(shí)現(xiàn)多行多列布局,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • Android 仿微信數(shù)字鍵盤

    Android 仿微信數(shù)字鍵盤

    大部分的金融App會(huì)對默認(rèn)的數(shù)字鍵盤進(jìn)行處理,以實(shí)現(xiàn)自定義的數(shù)字安全鍵盤。基于此,本文對對微信數(shù)字鍵盤樣式進(jìn)行了仿寫,實(shí)現(xiàn)了一套自定義的數(shù)字安全鍵盤(支持隨機(jī)數(shù)字分布)。
    2021-05-05
  • Android 網(wǎng)絡(luò)圖片查看顯示的實(shí)現(xiàn)方法

    Android 網(wǎng)絡(luò)圖片查看顯示的實(shí)現(xiàn)方法

    本篇文章小編為大家介紹,Android 網(wǎng)絡(luò)圖片查看顯示的實(shí)現(xiàn)方法,需要的朋友參考下
    2013-04-04

最新評論

乌拉特后旗| 盐边县| 龙陵县| 秦皇岛市| 北宁市| 大宁县| 行唐县| 马公市| 河池市| 宁海县| 安庆市| 石泉县| 雅江县| 东台市| 会宁县| 资溪县| 新民市| 长寿区| 苏尼特右旗| 沙河市| 湛江市| 焉耆| 汨罗市| 巴楚县| 瑞安市| 扶沟县| 黄梅县| 定边县| 乌海市| 瓦房店市| 古丈县| 宝兴县| 安西县| 萨嘎县| 沙田区| 甘孜| 连山| 长治市| 繁峙县| 巍山| 开阳县|