日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > Android >内容正文

Android

Android抽屉页面效果

發(fā)布時(shí)間:2025/3/15 Android 12 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android抽屉页面效果 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>

DrawerLayout抽屜布局,現(xiàn)在主流App是越來越多使用DrawerLayout,因?yàn)檫@樣出來的效果是比較炫酷的吧!其實(shí)抽屜界面很簡(jiǎn)單,沒有網(wǎng)上說的那么復(fù)雜,今天我就給大家介紹一種比較簡(jiǎn)單的抽屜布局,DrawerLayout,


效果圖:



1:主布局文件(分為2塊,第一塊是主頁(yè)面內(nèi)容,第二塊是抽屜頁(yè)面內(nèi)容,這是固定的,必須是這樣的格式)

<LinearLayout xmlns:android= "http://schemas.android.com/apk/res/android"
???
xmlns:tools= "http://schemas.android.com/tools"
???
android:layout_width="match_parent"
???
android:layout_height="match_parent"
???
android:orientation="vertical"
???
android:paddingBottom="@dimen/activity_vertical_margin"
???
android:paddingLeft="@dimen/activity_horizontal_margin"
???
android:paddingRight="@dimen/activity_horizontal_margin"
???
android:paddingTop="@dimen/activity_vertical_margin"
???
tools:context=".MainActivity" >

??? <
android.support.v4.widget.DrawerLayout
???????
android :id="@+id/drawer_layout"
???????
android :layout_width="match_parent"
???????
android :layout_height="match_parent">
???????
???????
<!-- 主界面-->
???????
???????
<LinearLayout
???????????
android:id="@+id/content_frame"
???????????
android:layout_width="match_parent"
???????????
android:layout_height="match_parent"
???????????
android:background="#FF0000">

??????????? <
Button
???????????????
android:id= "@+id/btn"
???????????????
android:layout_width= "match_parent"
???????????????
android:layout_height= "wrap_content"
???????????????
android:text= "open" />

??????? </
LinearLayout >


??????? <!-- 抽屜界面 --> //抽屜頁(yè)面可以是一個(gè)Fragment,或者是ListView,什么都可以,這里以Fragment為列子,因?yàn)镕ragment可以添加一個(gè)布局文件


???????
<FrameLayout
???????????
android:id="@+id/fragment_layout"
???????????
android:layout_width="match_parent"
???????????
android:layout_height="match_parent"
???????????
android:layout_gravity="start"//從左邊滑動(dòng)進(jìn)來,右邊是end,一定要寫,不然沒有效果
???????????
android:background="#9053ff59"></ FrameLayout>
??? </
android.support.v4.widget.DrawerLayout >

</LinearLayout >

2:Fragment布局文件

<?xml version="1.0" encoding="utf-8"?>
<
LinearLayout xmlns:android= "http://schemas.android.com/apk/res/android"
???
android:layout_width="match_parent"
???
android:layout_height="match_parent"
???
android:orientation="vertical" >
??? <
Button
???????
android :layout_width="match_parent"
???????
android :layout_height="wrap_content"
???????
android :text="按鈕一"/>
??? <
Button
???????
android :layout_width="match_parent"
???????
android :layout_height="wrap_content"
???????
android :text="按鈕二"/>

??? <
Button
???????
android :id="@+id/item_frgment_bt"
???????
android :layout_width="match_parent"
???????
android :layout_height="wrap_content"
???????
android :text="按鈕三"/>

??? <
Button
???????
android :layout_width="match_parent"
???????
android :layout_height="wrap_content"
???????
android :text="按鈕四"/>


</LinearLayout >

4:Fragment類

package com.example.yangjie.drawerlayout;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

/**
* Created by Administrator on 2015/10/17.
*/
public class DrawerFragment extends Fragment {
???
@Nullable
??? @Override
???
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
???????
return inflater.inflate(R.layout.item_frgement,container,false);//將布局文件綁定到Fragment中
??? }

???
@Override
???
public void onViewCreated(View view, Bundle savedInstanceState) {
???????
super .onViewCreated(view, savedInstanceState);

??????? Button? button=(Button)view.findViewById(R.id.item_frgment_bt);

??????? button.setOnClickListener(new View.OnClickListener() { //給抽屜界面的按鈕散設(shè)置了一個(gè)箭頭

??????????? @Override
???????????
public void onClick(View v) {
??????????????? Toast.
makeText (getActivity(),
"點(diǎn)擊了按鈕3" ,Toast.LENGTH_SHORT).show();
??????????? }
??????? });
??? }

}

5:Activity

public class MainActivity extends AppCompatActivity {
???
private DrawerLayout mDrawerLayout = null ;
???
@Override
???
protected void onCreate(Bundle savedInstanceState) {
???????
super .onCreate(savedInstanceState);

??????? setContentView(R.layout.activity_main);


??????? FragmentManager fragmentManager=getFragmentManager();
??????? FragmentTransaction ft=fragmentManager.beginTransaction();

??????? DrawerFragment? drawerFragment=new DrawerFragment();

??????? ft.add(R.id.fragment_layout,drawerFragment,"標(biāo)簽1");//將fragment綁定到已經(jīng)占有位置的FrameLayout中

??????? ft.commit();


??????? mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

??????? Button button = (Button) findViewById(R.id.
btn);
??????? button.setOnClickListener(
new View.OnClickListener() {

???????????
@Override
???????????
public void onClick(View v) {
???????????????
// 按鈕按下,將抽屜打開
???????????????
mDrawerLayout.openDrawer(Gravity. LEFT); //從左打開

??????????? }
??????? });
??? }

}



轉(zhuǎn)載于:https://my.oschina.net/u/2502508/blog/537409

總結(jié)

以上是生活随笔為你收集整理的Android抽屉页面效果的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。