Android相对布局+圆角按钮+Shape样式

2024-06-18 02:18

本文主要是介绍Android相对布局+圆角按钮+Shape样式,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

又开始了android布局的学习,经过之前的书籍的浏览,大体了解了,看的时候就会联想到qt的布局,其实很多布局模型的大同小异,什么帧布局、线性布局、相对布局、绝对布局啊之类的,总是想要彻底了解还是挺麻烦的,而且学习过程中需要了解一些尺寸的知识,像dip、px、sp这些东西之后,进行参数的设置时才会比较有概念,我是不行了。呵呵............

     我打算做个相对布局的模型,之后基于这个模型进行一系列的学习【包括横竖屏、控件动画等 】,实现一些简单的功能,加深对一些理论的实践性的理解;一步一步来吗!

    这个就是今天的一个小效果,感谢网友的分享,让我学到了很多,最重要的一点就是当我发现效果和想的不一样的时候,开始找资料,各种试试,然后回过头来看手册的参数说明,才想到设置一个参数就能解决问题,此时还是很高兴的,体会过程,都是经验啊!!!

    总体效果就是这样【UI很丑】:
    
    
    相对布局文件【文中注释的地方就是后来发现需要这样才可以达到效果、菜鸟一个、所以才纠结这么久】:res/layout/center.xml

点击(此处)折叠或打开

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:layout_width="fill_parent"
  4.     android:layout_height="fill_parent"
  5.     android:orientation="vertical"
  6.     android:background="@drawable/back_ground" >

  7.     <RelativeLayout
  8.         android:id="@+id/RelativeLayout_with_center"
  9.         android:layout_width="fill_parent"
  10.         android:layout_height="fill_parent" >

  11.         <!-- 屏幕中心按钮设置 android:layout_centerInParent="true" -->
  12.         <Button
  13.             android:id="@+id/center_menu_button"
  14.             android:layout_width="wrap_content"
  15.             android:layout_height="wrap_content"
  16.             android:layout_centerInParent="true"
  17.             android:background="@drawable/button" />

  18.         <!-- 屏幕中心按钮左侧按钮,此时需要设置垂直居中 android:layout_centerVertical="true" -->
  19.         <Button
  20.             android:id="@+id/left_button"
  21.             android:layout_width="wrap_content"
  22.             android:layout_height="wrap_content"
  23.             android:layout_centerVertical="true"
  24.             android:layout_toLeftOf="@+id/center_menu_button"
  25.             android:background="@drawable/round_button"
  26.             android:text="亲,评价" />

  27.         <!-- 屏幕中心按钮右侧侧按钮,此时需要设置垂直居中 android:layout_centerVertical="true" -->
  28.         <Button
  29.             android:id="@+id/right_button"
  30.             android:layout_width="wrap_content"
  31.             android:layout_height="wrap_content"
  32.             android:layout_centerVertical="true"
  33.             android:layout_toRightOf="@+id/center_menu_button"
  34.             android:background="@drawable/round_button"
  35.             android:text="退出游戏" />

  36.         <!-- 屏幕中心按钮上方按钮,此时需要设置水平居中 android:layout_centerHorizontal="true" -->
  37.         <Button
  38.             android:id="@+id/top_button"
  39.             android:layout_width="wrap_content"
  40.             android:layout_height="wrap_content"
  41.             android:layout_centerHorizontal="true"
  42.             android:layout_above="@+id/center_menu_button"
  43.             android:background="@drawable/round_button"
  44.             android:text="进入游戏" />

  45.          <!-- 屏幕中心按钮下方按钮,此时需要设置水平居中 android:layout_centerHorizontal="true" -->
  46.         <Button
  47.             android:id="@+id/below_button"
  48.             android:layout_width="wrap_content"
  49.             android:layout_height="wrap_content"
  50.             android:layout_centerHorizontal="true"
  51.             android:layout_below="@+id/center_menu_button"
  52.             android:background="@drawable/round_button"
  53.             android:text="关于我们" />
  54.     </RelativeLayout>

  55. </LinearLayout>
    中心按钮样式文件: res/drawable-hdpi/button.xml

点击(此处)折叠或打开

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <selector xmlns:android="http://schemas.android.com/apk/res/android" >
  3.     <!-- 获得焦点但未按下时的背景图片 -->
  4.     <!-- <item android:state_focused="true" android:state_enabled="true" android:state_pressed="false" android:drawable="@drawable/user_selecte_n" /> -->
  5.     <!-- 按下时的背景图片 -->
  6.     <item android:state_enabled="true" android:state_pressed="true" android:drawable="@drawable/center_light" />
  7.     <!-- 按下时的背景图片 -->
  8.     <!-- <item android:state_enabled="true" android:state_checked="true" android:drawable="@drawable/center_light" /> -->
  9.     <!-- 默认时的背景图片 -->
  10.     <item android:drawable="@drawable/center" />
  11. </selector>
    四边按钮样式文件: res/drawable-hdpi/round_button.xml

点击(此处)折叠或打开

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <selector xmlns:android="http://schemas.android.com/apk/res/android">
  3.     <item android:state_pressed="false">
  4.            <shape android:shape="rectangle" >
  5.             <!-- 填充的颜色 -->
  6.             <solid android:color="#0FFFFF" />
  7.             <!-- 设置按钮的四个角为弧形 -->
  8.             <!-- android:radius 弧形的半径 -->
  9.             <corners android:radius="15dip" />
  10.             <!-- padding:Button里面的文字与Button边界的间隔 -->
  11.             <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
  12.         </shape>
  13.     </item>
  14.     <item android:state_pressed="true">
  15.      <shape android:shape="rectangle">
  16.             <solid android:color="#FFFF0F" />
  17.             <corners android:radius="15dip" />
  18.          </shape>
  19.     </item> 
  20. </selector>
    至于背景啊、名称啥的,都知道....然后还是留一份图片资源到网盘吧,省的系统重装了,还得现搜......

http://pan.baidu.com/share/link?shareid=3336646398&uk=3927989065

这篇关于Android相对布局+圆角按钮+Shape样式的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1071027

相关文章

Python实现Excel批量样式修改器(附完整代码)

《Python实现Excel批量样式修改器(附完整代码)》这篇文章主要为大家详细介绍了如何使用Python实现一个Excel批量样式修改器,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一... 目录前言功能特性核心功能界面特性系统要求安装说明使用指南基本操作流程高级功能技术实现核心技术栈关键函

Android协程高级用法大全

《Android协程高级用法大全》这篇文章给大家介绍Android协程高级用法大全,本文结合实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友跟随小编一起学习吧... 目录1️⃣ 协程作用域(CoroutineScope)与生命周期绑定Activity/Fragment 中手

Android 缓存日志Logcat导出与分析最佳实践

《Android缓存日志Logcat导出与分析最佳实践》本文全面介绍AndroidLogcat缓存日志的导出与分析方法,涵盖按进程、缓冲区类型及日志级别过滤,自动化工具使用,常见问题解决方案和最佳实... 目录android 缓存日志(Logcat)导出与分析全攻略为什么要导出缓存日志?按需过滤导出1. 按

Python清空Word段落样式的三种方法

《Python清空Word段落样式的三种方法》:本文主要介绍如何用python-docx库清空Word段落样式,提供三种方法:设置为Normal样式、清除直接格式、创建新Normal样式,注意需重... 目录方法一:直接设置段落样式为"Normal"方法二:清除所有直接格式设置方法三:创建新的Normal样

Android Paging 分页加载库使用实践

《AndroidPaging分页加载库使用实践》AndroidPaging库是Jetpack组件的一部分,它提供了一套完整的解决方案来处理大型数据集的分页加载,本文将深入探讨Paging库... 目录前言一、Paging 库概述二、Paging 3 核心组件1. PagingSource2. Pager3.

SpringBoot+EasyExcel实现自定义复杂样式导入导出

《SpringBoot+EasyExcel实现自定义复杂样式导入导出》这篇文章主要为大家详细介绍了SpringBoot如何结果EasyExcel实现自定义复杂样式导入导出功能,文中的示例代码讲解详细,... 目录安装处理自定义导出复杂场景1、列不固定,动态列2、动态下拉3、自定义锁定行/列,添加密码4、合并

Android kotlin中 Channel 和 Flow 的区别和选择使用场景分析

《Androidkotlin中Channel和Flow的区别和选择使用场景分析》Kotlin协程中,Flow是冷数据流,按需触发,适合响应式数据处理;Channel是热数据流,持续发送,支持... 目录一、基本概念界定FlowChannel二、核心特性对比数据生产触发条件生产与消费的关系背压处理机制生命周期

Android ClassLoader加载机制详解

《AndroidClassLoader加载机制详解》Android的ClassLoader负责加载.dex文件,基于双亲委派模型,支持热修复和插件化,需注意类冲突、内存泄漏和兼容性问题,本文给大家介... 目录一、ClassLoader概述1.1 类加载的基本概念1.2 android与Java Class

Android DataBinding 与 MVVM使用详解

《AndroidDataBinding与MVVM使用详解》本文介绍AndroidDataBinding库,其通过绑定UI组件与数据源实现自动更新,支持双向绑定和逻辑运算,减少模板代码,结合MV... 目录一、DataBinding 核心概念二、配置与基础使用1. 启用 DataBinding 2. 基础布局

Android ViewBinding使用流程

《AndroidViewBinding使用流程》AndroidViewBinding是Jetpack组件,替代findViewById,提供类型安全、空安全和编译时检查,代码简洁且性能优化,相比Da... 目录一、核心概念二、ViewBinding优点三、使用流程1. 启用 ViewBinding (模块级