安卓初学之qq侧滑功能的实现
作为一个安卓初学者,今天看了慕课网的仿照qq的侧滑功能的相关视频,觉得感触很深。特地把一些学到的知识写出来和大家分享一下~~
(一)需要了解的一些小知识
①ViewGroup是安卓里的一个类,通过查询安卓的api文档得知,它继承自android.view.View,然后呢大家所熟悉的FramLayout,GridLayout,LinearLayout,RelativeLayout这些布局都是从它继承下来的。
②实现qq的功能需要引入一个第三方的jar包,名字叫做nineoldandroids,大家百度一下,很容易就可以找到地方下载。
(二)实现的大概逻辑
①最主要的布局就是HorizontalScrollView,隐藏掉它的滚动条,然后对其进行自定义。
②在HorizontalScrollView下有俩个大的布局,一个布局在就是左边那个滑出来的menu菜单,可以通过LinearLayout或者RelativeLayout等任意布局实现。不过呢我建议还是通过RelativeLayout里面套一个LinearLayout的方式来进行实现,把头像,设置和夜间模式调到LinearLayout的外边,LinearLayout里面是N个RelativeLayout用于放在图标和Textview。
(三)相关的布局代码文件
这个是滑出来的布局
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:background="@drawable/img_1" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:layout_toRightOf="@+id/imageButton1"
android:text="这是第一个"
android:textSize="20sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp" >
<ImageButton

最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



