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

Android實(shí)現(xiàn)左側(cè)滑動(dòng)菜單

 更新時(shí)間:2022年02月16日 08:03:31   作者:風(fēng)云正  
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)左側(cè)滑動(dòng)菜單,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android實(shí)現(xiàn)左側(cè)滑動(dòng)菜單的具體代碼,供大家參考,具體內(nèi)容如下

效果圖:

SlideActivity.java:

package com.demo.slide;
?
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
?
import com.demo.broadcast.R;
?
public class SlideActivity extends Activity
{
?
?? ?private SlidingMenu mLeftMenu ;?
?? ?
?? ?@Override
?? ?protected void onCreate(Bundle savedInstanceState)
?? ?{
?? ??? ?super.onCreate(savedInstanceState);
?? ??? ?requestWindowFeature(Window.FEATURE_NO_TITLE);
?? ??? ?setContentView(R.layout.slide_main);
?? ??? ?
?? ??? ?mLeftMenu = (SlidingMenu) findViewById(R.id.id_menu);
?? ?}
?
?? ?public void toggleMenu(View view)
?? ?{
?? ??? ?mLeftMenu.toggle();
?? ?}
}

SlidingMenu.java:

package com.demo.slide;
?
import android.content.Context;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
?
public class SlidingMenu extends HorizontalScrollView
{
?? ?private LinearLayout mWapper;
?? ?private ViewGroup mMenu;
?? ?private ViewGroup mContent;
?? ?private int mScreenWidth;
?
?? ?private int mMenuWidth;
?? ?// dp
?? ?private int mMenuRightPadding = 80;
?
?? ?private boolean once;
?
?? ?private boolean isOpen;
?
?? ?/**
?? ? * 未使用自定義屬性時(shí),調(diào)用
?? ? *?
?? ? * @param context
?? ? * @param attrs
?? ? */
?? ?public SlidingMenu(Context context, AttributeSet attrs)
?? ?{
?? ??? ?this(context, attrs, 0);
?? ?}
?
?? ?/**
?? ? * 當(dāng)使用了自定義屬性時(shí),會(huì)調(diào)用此構(gòu)造方法
?? ? *?
?? ? * @param context
?? ? * @param attrs
?? ? * @param defStyle
?? ? */
?? ?public SlidingMenu(Context context, AttributeSet attrs, int defStyle)
?? ?{
?? ??? ?super(context, attrs, defStyle);
?
?? ??? ?WindowManager wm = (WindowManager) context
?? ??? ??? ??? ?.getSystemService(Context.WINDOW_SERVICE);
?? ??? ?DisplayMetrics outMetrics = new DisplayMetrics();
?? ??? ?wm.getDefaultDisplay().getMetrics(outMetrics);
?? ??? ?mScreenWidth = outMetrics.widthPixels;
?? ??? ?mMenuRightPadding = (int) TypedValue.applyDimension(
?? ??? ??? ??? ?TypedValue.COMPLEX_UNIT_DIP, 50, context
?? ??? ??? ??? ?.getResources().getDisplayMetrics());
?? ?}
?
?? ?public SlidingMenu(Context context)
?? ?{
?? ??? ?this(context, null);
?? ?}
?
?? ?/**
?? ? * 設(shè)置子View的寬和高 設(shè)置自己的寬和高
?? ? */
?? ?@Override
?? ?protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
?? ?{
?? ??? ?if (!once)
?? ??? ?{
?? ??? ??? ?mWapper = (LinearLayout) getChildAt(0);
?? ??? ??? ?mMenu = (ViewGroup) mWapper.getChildAt(0);
?? ??? ??? ?mContent = (ViewGroup) mWapper.getChildAt(1);
?? ??? ??? ?
?? ??? ??? ?mMenuWidth = mMenu.getLayoutParams().width = mScreenWidth
?? ??? ??? ??? ??? ?- mMenuRightPadding;
?? ??? ??? ?mContent.getLayoutParams().width = mScreenWidth;
?? ??? ??? ?once = true;
?? ??? ?}
?? ??? ?super.onMeasure(widthMeasureSpec, heightMeasureSpec);
?? ?}
?
?? ?/**
?? ? * 通過(guò)設(shè)置偏移量,將menu隱藏
?? ? */
?? ?@Override
?? ?protected void onLayout(boolean changed, int l, int t, int r, int b)
?? ?{
?? ??? ?super.onLayout(changed, l, t, r, b);
?? ??? ?if (changed)
?? ??? ?{
?? ??? ??? ?this.scrollTo(mMenuWidth, 0);
?? ??? ?}
?? ?}
?
?? ?@Override
?? ?public boolean onTouchEvent(MotionEvent ev)
?? ?{
?? ??? ?int action = ev.getAction();
?? ??? ?switch (action)
?? ??? ?{
?? ??? ?case MotionEvent.ACTION_UP:
?? ??? ??? ?// 隱藏在左邊的寬度
?? ??? ??? ?int scrollX = getScrollX();
?? ??? ??? ?if (scrollX >= mMenuWidth / 2)
?? ??? ??? ?{
?? ??? ??? ??? ?this.smoothScrollTo(mMenuWidth, 0);
?? ??? ??? ??? ?isOpen = false;
?? ??? ??? ?} else
?? ??? ??? ?{
?? ??? ??? ??? ?this.smoothScrollTo(0, 0);
?? ??? ??? ??? ?isOpen = true;
?? ??? ??? ?}
?? ??? ??? ?return true;
?? ??? ?}
?? ??? ?return super.onTouchEvent(ev);
?? ?}
?
?? ?/**
?? ? * 打開菜單
?? ? */
?? ?public void openMenu()
?? ?{
?? ??? ?if (isOpen)
?? ??? ??? ?return;
?? ??? ?this.smoothScrollTo(0, 0);
?? ??? ?isOpen = true;
?? ?}
?
?? ?public void closeMenu()
?? ?{
?? ??? ?if (!isOpen)
?? ??? ??? ?return;
?? ??? ?this.smoothScrollTo(mMenuWidth, 0);
?? ??? ?isOpen = false;
?? ?}
?
?? ?/**
?? ? * 切換菜單
?? ? */
?? ?public void toggle()
?? ?{
?? ??? ?if (isOpen)
?? ??? ?{
?? ??? ??? ?closeMenu();
?? ??? ?} else
?? ??? ?{
?? ??? ??? ?openMenu();
?? ??? ?}
?? ?}
}

slide_main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
? ? android:layout_width="match_parent"
? ? android:layout_height="match_parent" >

? ? <com.demo.slide.SlidingMenu
? ? ? ? android:id="@+id/id_menu"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="match_parent" >

? ? ? ? <LinearLayout
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="match_parent"
? ? ? ? ? ? android:orientation="horizontal" >

? ? ? ? ? ? <include layout="@layout/left_menu" />

? ? ? ? ? ? <LinearLayout
? ? ? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? ? ? android:layout_height="match_parent"
? ? ? ? ? ? ? ? android:background="#ffffff" >

? ? ? ? ? ? ? ? <Button
? ? ? ? ? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? ? ? android:onClick="toggleMenu"
? ? ? ? ? ? ? ? ? ? android:text="切換" />

? ? ? ? ? ? ? ? <TextView
? ? ? ? ? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? ? ? android:layout_gravity="center"
? ? ? ? ? ? ? ? ? ? android:layout_marginLeft="20dp"
? ? ? ? ? ? ? ? ? ? android:text="我是主content"
? ? ? ? ? ? ? ? ? ? android:textColor="#ff00ff"
? ? ? ? ? ? ? ? ? ? android:textSize="20sp" />
? ? ? ? ? ? </LinearLayout>
? ? ? ? </LinearLayout>
? ? </com.demo.slide.SlidingMenu>

</RelativeLayout>

left_menu.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
? ? android:layout_width="match_parent"
? ? android:layout_height="match_parent"
? ? android:background="#000000" >

? ? <LinearLayout
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:layout_centerInParent="true"
? ? ? ? android:orientation="vertical" >

? ? ? ? <TextView
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:layout_marginLeft="20dp"
? ? ? ? ? ? android:text="我是左側(cè)Menu"
? ? ? ? ? ? android:textColor="#ffffff"
? ? ? ? ? ? android:textSize="20sp" />

? ? </LinearLayout>

</RelativeLayout>

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

相關(guān)文章

  • Android定時(shí)器Timer的停止和重啟實(shí)現(xiàn)代碼

    Android定時(shí)器Timer的停止和重啟實(shí)現(xiàn)代碼

    本篇文章主要介紹了Android實(shí)現(xiàn)定時(shí)器Timer的停止和重啟實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • RxJava2和Retrofit2封裝教程(整潔、簡(jiǎn)單、實(shí)用)

    RxJava2和Retrofit2封裝教程(整潔、簡(jiǎn)單、實(shí)用)

    這篇文章主要給大家介紹了關(guān)于RxJava2和Retrofit2封裝的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),整潔、簡(jiǎn)單、實(shí)用,非常適合大家學(xué)習(xí)使用,需要的朋友可以參考下
    2018-11-11
  • Android本地實(shí)現(xiàn)搜索歷史記錄

    Android本地實(shí)現(xiàn)搜索歷史記錄

    這篇文章主要為大家詳細(xì)介紹了Android本地實(shí)現(xiàn)搜索歷史記錄,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-09-09
  • Android實(shí)現(xiàn)后臺(tái)開啟服務(wù)默默拍照功能

    Android實(shí)現(xiàn)后臺(tái)開啟服務(wù)默默拍照功能

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)后臺(tái)開啟服務(wù)默默拍照功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-06-06
  • android中實(shí)現(xiàn)OkHttp下載文件并帶進(jìn)度條

    android中實(shí)現(xiàn)OkHttp下載文件并帶進(jìn)度條

    本篇文章主要介紹了android中實(shí)現(xiàn)OkHttp下載文件并帶進(jìn)度條,OkHttp是比較火的網(wǎng)絡(luò)框架,它支持同步與異步請(qǐng)求,支持緩存,可以攔截,更方便下載大文件與上傳文件的操作,有興趣的可以了解一下
    2017-07-07
  • Android自帶emoji表情的使用方法詳解

    Android自帶emoji表情的使用方法詳解

    這篇文章主要為大家詳細(xì)介紹了Android自帶emoji表情的使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • TabLayout實(shí)現(xiàn)ViewPager指示器的方法

    TabLayout實(shí)現(xiàn)ViewPager指示器的方法

    這篇文章主要為大家詳細(xì)介紹了TabLayout實(shí)現(xiàn)ViewPager指示器,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-06-06
  • android 設(shè)置全屏的兩種方法

    android 設(shè)置全屏的兩種方法

    現(xiàn)在android的每一個(gè)項(xiàng)目都會(huì)需要設(shè)置為全屏,現(xiàn)在介紹兩種設(shè)置為全屏的方式
    2014-05-05
  • Android?數(shù)據(jù)結(jié)構(gòu)全面總結(jié)分析

    Android?數(shù)據(jù)結(jié)構(gòu)全面總結(jié)分析

    這篇文章主要為大家介紹了Android?數(shù)據(jù)結(jié)構(gòu)全面總結(jié)分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-12-12
  • OkHttp3中默認(rèn)不保持Cookie的解決方法

    OkHttp3中默認(rèn)不保持Cookie的解決方法

    這篇文章主要給大家介紹了關(guān)于OkHttp3中默認(rèn)不保持Cookie的解決方法,文中先對(duì)OKhttp3中的cookies進(jìn)行了簡(jiǎn)單的介紹,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-04-04

最新評(píng)論

樟树市| 宁明县| 黔江区| 克拉玛依市| 颍上县| 色达县| 务川| 遂昌县| 炉霍县| 西乡县| 安西县| 且末县| 攀枝花市| 富川| 宜川县| 宁城县| 九龙城区| 梅河口市| 安阳市| 南陵县| 宁南县| 枣庄市| 镇赉县| 射洪县| 胶南市| 漠河县| 庄浪县| 扶沟县| 彭水| 灌阳县| 行唐县| 宜君县| 凯里市| 清徐县| 宜春市| 花莲县| 清远市| 哈密市| 余姚市| 垫江县| 鄂温|