首页 文章 精选 留言 我的

精选列表

搜索[droid],共111篇文章
优秀的个人博客,低调大师

droid用户界面-布局管理Layout

在 Android 中各种布局的应用,以及菜单效果的实现 各种布局方式的应用,FrameLayout, LinearLayout, TableLayout, AbsoluteLayout, RelativeLayout 为指定元素配置上下文菜单,为应用程序配置选项菜单,以及多级菜单的实现 各种布局方式的演示res/layout/main.xml <?xmlversion="1.0"encoding="utf-8"?> <!-- layout_width-宽。fill_parent:宽度跟着父元素走;wrap_content:宽度跟着本身的内容走;直接指定一个px值来设置宽 layout_height-高。fill_parent:高度跟着父元素走;wrap_content:高度跟着本身的内容走;直接指定一个px值来设置高 --> <!-- LinearLayout-线形布局。 orientation-容器内元素的排列方式。vertical:子元素们垂直排列;horizontal:子元素们水平排列 gravity-内容的排列形式。常用的有top,bottom,left,right,center等,详见文档 --> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"android:gravity="right" android:layout_width="fill_parent"android:layout_height="fill_parent"> <!-- FrameLayout-层叠式布局。以左上角为起点,将FrameLayout内的元素一层覆盖一层地显示 --> <FrameLayoutandroid:layout_height="wrap_content" android:layout_width="fill_parent"> <TextViewandroid:layout_width="wrap_content" android:layout_height="wrap_content"android:text="FrameLayout"> </TextView> <TextViewandroid:layout_width="wrap_content" android:layout_height="wrap_content"android:text="FrameLayout"> </TextView> </FrameLayout> <TextViewandroid:layout_width="wrap_content" android:layout_height="wrap_content"android:text="@string/hello"/> <!-- TableLayout-表格式布局。 TableRow-表格内的行,行内每一个元素算作一列 collapseColumns-设置TableLayout内的TableRow中需要隐藏的列的列索引,多个用“,”隔开 stretchColumns-设置TableLayout内的TableRow中需要拉伸(该列会拉伸到所有可用空间)的列的列索引,多个用“,”隔开 shrinkColumns-设置TableLayout内的TableRow中需要收缩(为了使其他列不会被挤到屏幕外,此列会自动收缩)的列的列索引,多个用“,”隔开 --> <TableLayoutandroid:id="@+id/TableLayout01" android:layout_width="fill_parent"android:layout_height="wrap_content" android:collapseColumns="1"> <TableRowandroid:id="@+id/TableRow01"android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextViewandroid:layout_width="wrap_content" android:layout_weight="1"android:layout_height="wrap_content" android:text="行1列1"/> <TextViewandroid:layout_width="wrap_content" android:layout_weight="1"android:layout_height="wrap_content" android:text="行1列2"/> <TextViewandroid:layout_width="wrap_content" android:layout_weight="1"android:layout_height="wrap_content" android:text="行1列3"/> </TableRow> <TableRowandroid:id="@+id/TableRow01"android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextViewandroid:layout_width="wrap_content" android:layout_height="wrap_content"android:text="行2列1"/> </TableRow> </TableLayout> <!-- AbsoluteLayout-绝对定位布局。 layout_x-x坐标。以左上角为顶点 layout_y-y坐标。以左上角为顶点 --> <AbsoluteLayoutandroid:layout_height="wrap_content" android:layout_width="fill_parent"> <TextViewandroid:layout_width="wrap_content" android:layout_height="wrap_content"android:text="AbsoluteLayout" android:layout_x="100px" android:layout_y="100px"/> </AbsoluteLayout> <!-- RelativeLayout-相对定位布局。 layout_centerInParent-将当前元素放置到其容器内的水平方向和垂直方向的中央位置(类似的属性有:layout_centerHorizontal,layout_alignParentLeft等) layout_marginLeft-设置当前元素相对于其容器的左侧边缘的距离 layout_below-放置当前元素到指定的元素的下面 layout_alignRight-当前元素与指定的元素右对齐 --> <RelativeLayoutandroid:id="@+id/RelativeLayout01" android:layout_width="fill_parent"android:layout_height="fill_parent"> <TextViewandroid:layout_width="wrap_content"android:id="@+id/abc" android:layout_height="wrap_content"android:text="centerInParent=true" android:layout_centerInParent="true"/> <TextViewandroid:layout_width="wrap_content" android:layout_height="wrap_content"android:text="marginLeft=20px" android:layout_marginLeft="20px"/> <TextViewandroid:layout_width="wrap_content" android:layout_height="wrap_content"android:text="xxx" android:layout_below="@id/abc"android:layout_alignRight="@id/abc"/> </RelativeLayout> </LinearLayout> res/values/strings.xml <?xmlversion="1.0"encoding="utf-8"?> <resources> <stringname="hello">HelloLayout</string> <stringname="app_name">webabcd_layout</string> </resources> Main.java packagecom.webabcd.layout; importandroid.app.Activity; importandroid.os.Bundle; publicclassMainextendsActivity{ /**Calledwhentheactivityisfirstcreated.*/ @Override publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); } } 本文转自linzheng 51CTO博客,原文链接:http://blog.51cto.com/linzheng/1080699

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

droid应用程序键盘(Keyboard)消息处理机制分析(10)

Step 2.ViewRoot.requestLayout 这个函数定义在frameworks/base/core/java/android/view/ViewRoot.java文件中: publicfinalclassViewRootextendsHandlerimplementsViewParent, View.AttachInfo.Callbacks{ ...... publicvoidrequestLayout(){ ...... mLayoutRequested=true; scheduleTraversals(); } ...... } 这个函数调用了scheduleTraversals函数来进一步执行操作,由于篇幅关系,我们就不详细描述scheduleTraversals函数了,简单来说,在scheduleTraversals函数中,会通过sendEmptyMessage(DO_TRAVERSAL)发送一个消息到应用程序的消息队列中,这个消息最终由ViewRoot的handleMessage函数处理,而ViewRoot的handleMessage函数把这个消息交给ViewRoot类的performTraversals来处理,在performTraversals函数中,又会调用ViewRoot类的relayoutWindow函数来进一步执行操作,最后在relayoutWindow函数中,就会通过WindowManagerService内部类Session的远程接口sWindowSession的relayout函数来进入到WindowManagerService中。 Step 3.WindowManagerService.Session.relayout 这个函数定义在frameworks/base/services/java/com/android/server/WindowManagerService.java文件中: publicclassWindowManagerServiceextendsIWindowManager.Stub implementsWatchdog.Monitor{ ...... privatefinalclassSessionextendsIWindowSession.Stub implementsIBinder.DeathRecipient{ ...... publicintrelayout(IWindowwindow,WindowManager.LayoutParamsattrs, intrequestedWidth,intrequestedHeight,intviewFlags, booleaninsetsPending,RectoutFrame,RectoutContentInsets, RectoutVisibleInsets,ConfigurationoutConfig,SurfaceoutSurface){ //Log.d(TAG,">>>>>>ENTEREDrelayoutfrom"+Binder.getCallingPid()); intres=relayoutWindow(this,window,attrs, requestedWidth,requestedHeight,viewFlags,insetsPending, outFrame,outContentInsets,outVisibleInsets,outConfig,outSurface); //Log.d(TAG,"<<<<<<EXITINGrelayoutto"+Binder.getCallingPid()); returnres; } ...... } ...... } 这个函数只是简单地调用WindowManagerService的成员函数relayoutWIndow来进一步处理。 Step 4.WindowManagerService.relayoutWIndow 这个函数定义在frameworks/base/services/java/com/android/server/WindowManagerService.java文件中: publicclassWindowManagerServiceextendsIWindowManager.Stub implementsWatchdog.Monitor{ ...... publicintrelayoutWindow(Sessionsession,IWindowclient, WindowManager.LayoutParamsattrs,intrequestedWidth, intrequestedHeight,intviewVisibility,booleaninsetsPending, RectoutFrame,RectoutContentInsets,RectoutVisibleInsets, ConfigurationoutConfig,SurfaceoutSurface){ ...... synchronized(mWindowMap){ ...... mInputMonitor.updateInputWindowsLw(); } ...... } ...... } 这个函数又会继续调用mInputMonitor的updateInputWindowsLw成员函数来更新当前的输入窗口,mInputMonitor是WindowManagerService的成员变量,它的类型为InputMonitor。 Step 5.InputMonitor.updateInputWindowsLw 这个函数定义在frameworks/base/services/java/com/android/server/WindowManagerService.java文件中: publicclassWindowManagerServiceextendsIWindowManager.Stub implementsWatchdog.Monitor{ ...... finalclassInputMonitor{ ...... /*Updatesthecachedwindowinformationprovidedtotheinputdispatcher.*/ publicvoidupdateInputWindowsLw(){ //Populatetheinputwindowlistwithinformationaboutallofthewindowsthat //couldpotentiallyreceiveinput. //Asanoptimization,wecouldtrytoprunethelistofwindowsbutthisturns //outtobedifficultbecauseonlythenativecodeknowsforsurewhichwindow //currentlyhastouchfocus. finalArrayList<WindowState>windows=mWindows; finalintN=windows.size(); for(inti=N-1;i>=0;i--){ finalWindowStatechild=windows.get(i); if(child.mInputChannel==null||child.mRemoved){ //Skipthiswindowbecauseitcannotpossiblyreceiveinput. continue; } ...... //Addawindowtoourlistofinputwindows. finalInputWindowinputWindow=mTempInputWindows.add(); ...... } //Sendwindowstonativecode. mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray()); ...... } ...... } ...... } 这个函数将当前系统中带有InputChannel的Activity窗口都设置为InputManager的输入窗口,但是后面我们会看到,只有当前激活的窗口才会响应键盘消息。 Step 6.InputManager.setInputWindows 这个函数定义在frameworks/base/services/java/com/android/server/InputManager.java文件中: publicclassInputManager{ ...... publicvoidsetInputWindows(InputWindow[]windows){ nativeSetInputWindows(windows); } ...... } 这个函数调用了本地方法nativeSetInputWindows来进一步执行操作。 Step 7.InputManager.nativeSetInputWindows 这个函数定义在frameworks/base/services/jni/com_android_server_InputManager.cpp文件中: staticvoidandroid_server_InputManager_nativeSetInputWindows(JNIEnv*env,jclassclazz, jobjectArraywindowObjArray){ if(checkInputManagerUnitialized(env)){ return; } gNativeInputManager->setInputWindows(env,windowObjArray); } 这里的gNativeInputManager我们前面分析InputManager的启动过程时已经见过了,这是一个本地InputManager对象,通过它进一步设置当前系统的输入窗口。 本文转自 Luoshengyang 51CTO博客,原文链接:xxxxxxx,如需转载请自行联系原作者

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

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

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册