首页 文章 精选 留言 我的

精选列表

搜索[小程序开发],共10000篇文章
优秀的个人博客,低调大师

安卓开发_自定义控件_界面的简单侧滑

主界面 package com.itheima.news; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.Window; public class NewsHomeActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //去掉头信息 requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_news_home); } } <RelativeLayout 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" > <com.itheima.news.MenuListGrouView android:layout_width="match_parent" android:layout_height="match_parent" > <include layout="@layout/item_menu_list" /> <include layout="@layout/main_showpage" /> </com.itheima.news.MenuListGrouView> </RelativeLayout> 显示布局文件1 <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="200dp" android:layout_height="match_parent" > <LinearLayout android:layout_width="200dp" android:layout_height="match_parent" android:background="@drawable/menu_bg" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:drawableLeft="@drawable/tab_dingyue" android:gravity="center" android:text="text1" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:drawableLeft="@drawable/tab_juhe" android:gravity="center" android:text="text1" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:drawableLeft="@drawable/tab_local" android:gravity="center" android:text="text1" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:drawableLeft="@drawable/tab_news" android:gravity="center" android:text="text1" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:drawableLeft="@drawable/tab_ties" android:gravity="center" android:text="text1" /> </LinearLayout> </ScrollView> 显示布局文件2 <?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" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/top_bar_bg" android:gravity="center" android:padding="10dp" android:text="我的小新闻 " android:textSize="20sp" /> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:text="点击浏览内容 " /> </LinearLayout> 自定义控件 的页面 public class MenuListGrouView extends ViewGroup { private int downX; private int interDownX; private int interDownY; public MenuListGrouView(Context context) { this(context,null); } public MenuListGrouView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public MenuListGrouView(Context context, AttributeSet attrs) { this(context, attrs,-1); } //对子控件进行测量 @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); //获取子控件 View liftMenuView = getChildAt(0); View rightMainView = getChildAt(1); //对子控件进行测量 rightMainView.measure(widthMeasureSpec, heightMeasureSpec); liftMenuView.measure(liftMenuView.getLayoutParams().width, heightMeasureSpec); } //进行排版设置 @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { //找到相关控件 View liftMenuView = getChildAt(0); View rightMainView = getChildAt(1); //对控件进行排版 rightMainView.layout(l, t, r, b); liftMenuView.layout(-liftMenuView.getMeasuredWidth(), 0,0, b); } @Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: //获取按下时的坐标 downX = (int) event.getX(); break; case MotionEvent.ACTION_MOVE: int moveX = (int) event.getX(); //计算偏移量 int shiftingX =downX -moveX ; //判断边界 int scrollX = getScrollX()+shiftingX; if (scrollX>0) { scrollTo(0, 0);//移动到指定的位置 } else if (scrollX<-getChildAt(0).getWidth()) { scrollTo(-getChildAt(0).getWidth(), 0); } else { //在上一次的移动的基础上进行移动 scrollBy(shiftingX,0); } downX = moveX ; break; case MotionEvent.ACTION_UP: //进行判断 int scrollUpX = (int) getScrollX(); if (scrollUpX>-getChildAt(0).getWidth()/2) { //如果向右滑动的距离小于右面控的一半的时候,那么就不显示右面的控件 scrollTo(0, 0); } else { //如果向右滑动的距离大于右面控件的一半的时候,那么就显示右面的控件 scrollTo(-getChildAt(0).getWidth(), 0); } break; default: break; } return true; } //消息传递机制来进行点击事件的滑动控制 @Override public boolean onInterceptTouchEvent(MotionEvent ev) { switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: interDownX = (int) ev.getX(); interDownY = (int) ev.getY(); break; case MotionEvent.ACTION_MOVE: int interMoveX = (int) ev.getX(); int interMoveY = (int) ev.getY(); //计算偏移量 int interShiftingX = Math.abs(interMoveX - interDownX); int interShiftingY = Math.abs( interMoveY - interDownY); if (interShiftingX>interShiftingY) { //说明是侧滑 return true; } case MotionEvent.ACTION_UP: break; default: break; } return super.onInterceptTouchEvent(ev); } } 效果图

优秀的个人博客,低调大师

CLion 2021.1 Beta 发布,C/C++ 跨平台集成开发环境

CLion 2021.1 Beta 已正式发布,新版本修复了项目模型和更多的 MISRA 检查。 主要更新内容 对于 Makefile 项目 更新 Makefile 项目所使用的工具链会触发项目的重新加载 提取大量项目的 make target 现在可以正常工作了 对于使用 MinGW 工具链的 Makefile 项目,CLion 现在可以在加载项目时正确处理带 "\" 和 "/" 的目录 对于汇编数据库项目 Clang-cl 现在支持此类项目 新的 MISRA C 和 C++ 检查 异常对象不应具有指针类型 一些新的检查现在禁止使用特定的库函数,例如 stdlib.h 的 bsearch 和 qsort,ctime 库的时间处理函数,或者 cstdlib 库的 atof、atoi 和 atol 详情请查看更新公告。

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册