首页 文章 精选 留言 我的

精选列表

搜索[原生UI],共10002篇文章
优秀的个人博客,低调大师

Android UI学习 - Linear Layout, RelativeLayout

1. 一些常用的公共属性介绍 1) layout_width- 宽 fill_parent: 宽度和父元素相同,wrap_content: 宽度随本身的内容所调整,或者指定 px 值来设置宽 2) layout_height -高 fill_parent: 高度和父元素相同,wrap_content: 高度随本身的内容所调整,或者指定 px 值来设置高 3) background - 设置背景图 4) padding - 设置边距 可以具体设置paddingBottom,paddingLeft,paddingRight,paddingTop来设定不同的px值 5) id - 该object的id号 @+id/id1 代表添加新的id名为id1, @id/id1 代表引用id1的控件 6) layout_weight - 重要度 个人理解为显示的优先级。默认为0(最高),数值越大,优先级越低!参考下面的Linear Layout例子。要让layout_weight生效,需要父层或父父层的相应layout_width/layout_height = "fill_parent",否则wrap_content会压缩到最小足够空间! 7) layout_gravity -Container组件的对齐方式 组件在layout里面的对齐方式。 8)gravity - 文字在组件里的对齐方式 例如设置button里面的文字在button中居中显示。 *大多数属性是可以调用对应的函数来动态改变状态的,请查看SDK Doc。 2. Linear Layout线形布局 orientation- 容器内元素的排列方式。vertical: 子元素们垂直排列,horizontal: 子元素们水平排列。在代码里可通过setOrientation()进行动态改变,值分别为HORIZONTAL或者VERTICAL。 * 在Linear Layout, 宽度/高度都是按着组件的次序逐个占用的!所以当某个组件设置"fill_parent",在没有设置Layout_weight的情况下,该组件会占用了余下的空间,那么在它后面的组件就会显示不出来。如下图的EditText如果没有设置android:layout_weight="1", 它下面的其他组件就看不见了! baselineAligned一般情况下,这个属性默认为true,代表在同一方向的组件都基于第一个组件对齐。所以可以看到下图的text1, button1, text2是在同一水平线的。当不需要这效果时,可以设置为false。 可以参考官方网页 http://androidappdocs.appspot.com/resources/tutorials/views/hello-linearlayout.html。 xml代码: <?xmlversion="1.0"encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:text="@string/hello" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:id="@+id/edittext" /> <LinearLayout android:id="@+id/LinearLayout01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:text="text1" android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Buttonandroid:text="Button01" android:id="@+id/Button01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" /> <TextView android:text="text2" android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="buttom" /> </LinearLayout> 3.RelativeLayout 相对定位布局 这个布局比较易懂,但组件间容易存在依赖关系,“牵一发而动全身“,所以在确定组件间布局关系不会再变动时,可以考虑采用!先看看xml代码: <?xmlversion="1.0"encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/relativelayout"> <ImageView android:id="@+id/image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/icon" /> <TextView android:id="@+id/text1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" android:layout_toRightOf="@id/image" /> <Button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="button1" android:layout_toRightOf="@id/image" android:layout_below="@id/text1" /> </RelativeLayout> Java代码(动态添加组件): publicclassRelativeDemoextendsActivity{ @Override publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.relative); RelativeLayout.LayoutParamslp=newRelativeLayout.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT,//width ViewGroup.LayoutParams.WRAP_CONTENT//height ); //设置editTextlayout_below="@id/button1" lp.addRule(RelativeLayout.BELOW,R.id.button1); //设置editTextlayout_alignLeft="@id/image" lp.addRule(RelativeLayout.ALIGN_LEFT,R.id.image); ((RelativeLayout)findViewById(R.id.relativelayout)).addView( newEditText(this),lp); } } 效果图: 先添加参照物(ImageView),然后就可以依次添加其他组件,定义位置规则rule!位置规则是不分先后的!另外ADT插件提供的预览图,有时候是不准的,未能及时更新,所以最好还是要到模拟器上测试! RelativeLayout的xml属性很多,总的来说分为2类: 1) 要指定参照物的,layout_alignBottom,layout_toLeftOf,layout_above,layout_alignBaseline系列的; layout_above = ”@id/text1“ 2) 以parent为参照物,设置true/false,layout_centerVertical,layout_alignParentLeft系列的。 layout_alignParentLeft = ”true“ 其中 layout_alignWithParentIfMissing是比较有用且要注意的属性,当设置为true,在指定的参照物找不到的情况下,会使用parent作为新的参照物! RelativeLayout.LayoutParams是用于设置位置规则的。上述的xml属性均来自此静态类。但它的AddRule(int verb, int anchor),参数的verb动作却是引用RelativeLayout的常量,而这些常量和部分xml属性相对应。参数anchor的值可能是参照物的id,RelativeLayout.TRUE,-1(当不需要指定anchor的verb)。可以这样理解verb和anchor: xml属性 (verb) = "value" (anchor) 其中它的构造函数之一: RelativeLayout.LayoutParams(int w, int h),参数指定所要设置子View的宽度和高度。 本文转自 Icansoft 51CTO博客,原文链接:http://blog.51cto.com/android/298345

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

Android UI控件常用库汇总

现在App的开发已经是非常成熟,涌现了一大批开源的工具。这些项目能够提高我们的搬砖效率。以下是一些在开发中比较常使用的控件和库。 ListView WaveSwipeRefreshLayout 水滴效果的下拉刷新 https://github.com/recruit-lifestyle/WaveSwipeRefreshLayout Phoenix 非常漂亮的下拉效果 https://github.com/Yalantis/Phoenix android-Ultra-Pull-To-Refresh 几乎支持所有的View https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh JellyRefreshLayout https://github.com/imallan/JellyRefreshLayout CircleRefreshLayout https://github.com/tuesda/CircleRefreshLayout WaterDropListView 水滴效果 https://github.com/THEONE10211024/WaterDropListView drag-sort-listview 拖动排序的ListView,滑动删除 https://github.com/bauerca/drag-sort-listview RecyclerViewSwipeDismiss RecycleView实现的滑动删除item https://github.com/CodeFalling/RecyclerViewSwipeDismiss PagedHeadListView 支持头部Page的ListView https://github.com/JorgeCastilloPrz/PagedHeadListView UltimateRecyclerView 非常强大的recycleview https://github.com/cymcsg/UltimateRecyclerView BaseRecyclerViewAdapterHelper 对recycleview的各种封装,也是非常方便 https://github.com/CymChad/BaseRecyclerViewAdapterHelper pinned-section-listview ListView滑动时分组title可以固定在分组内 https://github.com/beworker/pinned-section-listview ViewPager ViewPagerIndicator 与ViewPager一起使用indicator https://github.com/JakeWharton/ViewPagerIndicator JellyViewPager 带有动画切换效果 https://github.com/chiemy/JellyViewPager JazzyViewPager 滑动时支持各种切换动画 https://github.com/jfeinstein10/JazzyViewPager Android-DirectionalViewPager 垂直滑动的ViewPager https://github.com/JakeWharton/Android-DirectionalViewPager ImageView android-gif-drawable 显示gif动画 https://github.com/koral--/android-gif-drawable CircleImageView 圆形ImageView https://github.com/hdodenhof/CircleImageView TextView AndroidTagGroup 一个漂亮的标签控件 https://github.com/2dxgujun/AndroidTagGroup 键盘交互 JKeyboardPanelSwitch Android键盘面板冲突布局闪动处理方案 https://github.com/Jacksgong/JKeyboardPanelSwitch Material MaterialViewPager material风格的ViewPager,与Toolbar相结合 https://github.com/florent37/MaterialViewPager material-design-dimens 符合material design设计风格的color和dimens,可直接使用这个库的定义 https://github.com/DmitryMalkovich/material-design-dimens material-dialogs https://github.com/afollestad/material-dialogs 动画 Material-Animations material风格的动画 https://github.com/lgvalle/Material-Animations recyclerview-animators 为recycleview item添加动画 https://github.com/wasabeef/recyclerview-animators SmartTabLayout ViewPager头部导航栏滑动时的Tab,也有indicator https://github.com/ogaclejapan/SmartTabLayout FlycoTabLayout 底部导航栏,拥有各自样式,可以快速实现 https://github.com/H07000223/FlycoTabLayout 其他 easypermissions 权限相关提示 https://github.com/googlesamples/easypermissions AndroidSlidingUpPanel 向上拉出的面板 https://github.com/umano/AndroidSlidingUpPanel richeditor-android 富文本编辑器 https://github.com/wasabeef/richeditor-android android-viewbadger 消息提示小红点 https://github.com/jgilfelt/android-viewbadger 还可以关注我们的微信哦

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

Java 原生网络编程.

一、概念 Java 语言从其诞生开始,就和网络紧密联系在一起。在 1995 年的 Sun World 大会上,当时占浏览器市场份额绝对领先的网景公司宣布在浏览器中支持Java,从而引起一系列的公司产品对Java的支持,使得Java很快成为一种流行的语言。 Java 提供的网络功能的相关类主要有三个,它们分别是URL、Socket、Daragram。 二、URL 和URLConnection URL类代表一个统一资源定位符号,它是指向互联网资源的指针。是这三个类中层次级别最高或者说封装最多的类,通过URL可以直接发送或者读取网络上的数据。 public static void uRLTest(){ try { //URL:统一资源定位符(网址) URL url = new URL("http://www.baidu.com"); InputStream inputStream = url.openStream(); InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "UTF-8"); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); String line; while ((line = bufferedReader.readLine())!=null){ System.out.println(line); } } catch (UnknownHostException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } 前面介绍的 URL 类代表的是一个网络资源的位置,而URLConnection 代表的是一个连接,此类的实例可用于读取或者写入对应URL引用的资源。 public static void uRLConnectionTest(){ try { URL url = new URL("http://restapi.amap.com/v3/config/district?key=2c95fdacd3f72bdbfec55bd7eac7b5c0"); //1、创建连接对象 URLConnection urlConnection = url.openConnection(); HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection; //2、设置参数和一般请求属性 //应用程序要将参数写入URL连接 httpURLConnection.setDoOutput(true); //应用程序要向URL连接读取数据 httpURLConnection.setDoInput(true); //不使用缓存 httpURLConnection.setUseCaches(false); //设置请求参数 httpURLConnection.setRequestProperty("Content-type","application/json"); //设置请求方法 httpURLConnection.setRequestMethod("POST"); //3、使用connect方法建立到远程对象的实际链接 httpURLConnection.connect(); //4、远程对象变为输入输出流,根据需求进一步操作 InputStream inputStream = httpURLConnection.getInputStream(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream,"utf-8")); BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("E:\\data.json")); String line; while ((line = bufferedReader.readLine()) != null){ bufferedWriter.write(line); bufferedWriter.newLine(); bufferedWriter.flush(); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } 三、基于TCP的Socket编程 Socket也称为套接字,应用程序通常通过套接字向网络发出请求或者应答网络的请求。.Java 语言中的 Socket 编程常用到 Socket 和 ServerSocket 这两个类。 ServerSocket 用于服务端,而 Socket 是建立网络连接时使用的,在连接成功时,应用程序两端都会产生一个 Socket 实例,操作这个实例完成所需的会话。对于一个网络连接来说,套接字是平等的,不因为在服务端或者客户端而产生不同级别,不管是Socket还是ServerSocket,它们的工作都是通过SocketImpl类及其子类完成的。 TCP 的 Socket 编程示意图: 服务端程序: public static void main(String[] args) { try { System.out.println("启动服务器......"); //创建一个新的ServerSocket,用来监听指定端口上的连接请求 ServerSocket serverSocket = new ServerSocket(8989); Socket socket = null; while (true) { try { //对accept()方法的调用将被阻塞,直到一个连接创建 //该socket用于客户端和服务器之间的通信 //流对象都派生于该套接字的流对象 socket = serverSocket.accept(); InputStream inputStream = socket.getInputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(inputStream)); PrintWriter out = new PrintWriter(socket.getOutputStream(), true); String request, response; while ((request = in.readLine()) != null) { //如果客户端发送了exit,则退出循环 if ("exit".equals(request)) { break; } System.out.println("接收到客户端请求:" + request); //服务端处理方法 response ="客户端:" + socket.getInetAddress().getHostAddress() + " 请求," + processRequest(request); //响应给客户端 out.println(response); } } catch (Exception e) { System.out.println("Error"); } finally { socket.close(); } } } catch (IOException e) { e.printStackTrace(); } } 客户端程序: public static void main(String[] args) { Socket socket = null; try { socket = new Socket("192.168.1.22", 8989); //向服务器发送数据 //printWriter(字符流)/printStream(字节流) PrintWriter printWriter = new PrintWriter(socket.getOutputStream(), true); //接收服务器的反馈 InputStream inputStream = socket.getInputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(inputStream)); //模拟交互 BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String request, responese; while ((request = bf.readLine()) != null) { printWriter.println(request); responese = in.readLine(); System.out.println(responese); } } catch (IOException e) { e.printStackTrace(); } finally { try { socket.close(); } catch (IOException e) { e.printStackTrace(); } } } 四、基于UDP的Socket编程 UDP 是用户数据报协议,它提供的是无连接、不可靠信息传送服务。Java 主要提供两个类来实现基于 UDP 的 Socket 编程: DatagramSocket:此类表示用来发送和接收数据报包的套接字,数据报套接字是包投递服务的发送或接收点,每个在数据报套接字上发送或接收的包都是单独编址和路由的。在DatagramSocket上总是启用UDP广播发送。 DatagramPacket:此类表示数据报包。数据报包用来实现无连接包投递服务,每条报文仅根据该包中的信息从一台机器路由到另一台机器。 UDP 的 Socket 编程示例图: 服务端(接收端)程序: public static void main(String[] args) { DatagramSocket server = null; try { server = new DatagramSocket(8088); byte[] datas = new byte[1024]; //用一个字节数组接收UDP包,字节数组在传递给构造函数时是空的 DatagramPacket datagramPacket = new DatagramPacket(datas, datas.length); server.receive(datagramPacket); System.out.println(new String(datas)); } catch (SocketException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }finally { server.close(); } } 客户端(发送端)程序: public static void main(String[] args) { DatagramSocket client = null; try { client = new DatagramSocket(); //创建数据报 byte[] buffer = "hello,world".getBytes(); InetAddress byName = InetAddress.getByName("192.168.1.22"); //建立将要传输的UDP包,并指定ip地址和端口号 DatagramPacket datagramPacket = new DatagramPacket(buffer, buffer.length, byName, 8088); client.send(datagramPacket); } catch (SocketException e) { e.printStackTrace(); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { client.close(); } }

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

腾讯云软件源

腾讯云软件源

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

Rocky Linux

Rocky Linux

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

Sublime Text

Sublime Text

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

用户登录
用户注册
修改密码
忘记密码