1.textview 组件文本实现替换(快速实现字符资源的调用)

android 应用资源位置在 project(工程名)--->app--->res--->values

在strings.xml文件中进行相关设置,即可快速修改textview组件的文本内容

2.textview 组件字体大小修改(调用字符大小设置资源dimen.xml)

<1>首先在project(工程名)--->app--->res--->values目录下新建dimen.xml

<2>然后在activity_main.xml文件中设置对应关系

3.textview 组件字体颜色修改

<1>首先在project(工程名)--->app--->res--->values目录下调用colors.xml

<2>然后在activity_main.xml文件中设置对应关系

5.关于android布局属性tools:context最通俗的解释

  一般在根布局文件中会出现 tools:context = 某个activity名称。

这个属性的意思是:如果你在AndroidManifest.xml文件中为某个activity设置了Theme样式,那么,一般情况下,你在layout布局里面是无法直接看到这个效果的。因为一份layout布局可以提供给很多个activity用,layout无法知道自己提供给了哪个activity,而这个activity又设置了怎样的样式。所以,我们要为layout设置这样一个属性,来告诉layout当前提供给了哪个activity使用,从而实时显示这个activity所设置的样式效果(如果有)。

也就是,layout ---->   activity ---->Theme,建立起了链接。否则,即使你为activity设置了样式,你的layout布局文件也是不知道的。

6.背景颜色设置

android:background="#fffff0"

注意:区别前景与背景的不同

   <!--android:background="#ff00" 设置背景颜色-->
<!--android:src="@mipmap/ic_launcher" 设置前景图片-->
<ImageButton
android:src="@mipmap/ic_launcher"
android:background="#ff00"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

效果图:

红色为背景,Android图标为前景。

 7.设置ImageView图片控件布满整个屏幕

(1)xml文件设置(方式1)

android:scaleType="fitXY"

(2)java后台设置

iv_pic.setScaleType(ImageView.ScaleType.FIT_XY); //设置图片的缩放方式,宽高填充父控件

(3)使得图片自适应imageview的大小(通过裁减的方式)

<ImageView
android:src="@mipmap/image_demo"
android:scaleType="centerCrop"
android:layout_width="100dp"
android:layout_height="60dp" />

效果图:

8.组件的嵌套模板

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"> <TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="TextView" />
</android.support.v7.widget.Toolbar>

注意:android:layout_gravity="center" 这句代码实现了子容器在父容器内居中的效果

9.子容器放置于父容器的底部

app:layout_constraintBottom_toBottomOf="parent"

10. 组件常用的width(宽度)、height(高度)设置

  wrap_content 自适应大小,将强制性地使视图扩展以显示全部内容。以TextView和ImageView控件为例,设置为wrap_content将完整显示其内部的文本和图像。布局元素将根据内容更改大小。

  match_parent 将强制性地使构件扩展,以填充布局单元内尽可能多的空间

 11.设置多个按钮在页面居中

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"> <Button
android:id="@+id/btRg_exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="退出" /> <Button
android:id="@+id/btRg_submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="提交"
android:layout_marginLeft="20dp"/> </LinearLayout>
android:gravity="center_horizontal"   //这句的作用:设置该线性布局内的组件居中(即设置子容器在父容器内居中)
android:layout_marginLeft="20dp"     //这句的作用:设置组件与组件的间距(也可以设置子容器距离父容器的左边距,这样可以实现页面垂直方向对齐的效果)

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="您的手机防盗卫士:"
android:gravity="center_vertical" //设置textview控件中的文字垂直方向上居中
android:drawableLeft="@android:drawable/star_big_on" //在textview控件中放置一张图片,该图片位于文字的左边
android:textColor="#000"
android:layout_margin="5dp"
android:textSize="18dp" />

 12.让listview控件占满页面的剩余部分

<!--让listview占满页面的剩余部分-->
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"> </ListView>

将android:layout_height这个属性设置为0dp 且android:layout_weight="1" 即可实现需求。

注意:

  layout_weight(权重):剩余空间的分配规则。

  layout_weight 用于给一个线性布局中的诸多视图的重要度赋值。所有的视图都有一个layout_weight值,默认为零,意思是需要显示多大的视图就占据多大的屏幕空 间。若赋一个高于零的值,则将父视 图中的可用空间分割,分割大小具体取决于每一个视图的layout_weight 值以及该值在当前屏幕布局的整体 layout_weight值和在其它视图屏幕布局的layout_weight值中所占的比率而定。

13.将checkbox这个控件设置为无法选中状态

android:clickable="false"

android:focusableInTouchMode="false"

android:focusable="false"

以上3行设置checkbox为无法选中状态

<CheckBox
android:id="@+id/cb_process_manager"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:clickable="false"
android:focusableInTouchMode="false"
android:focusable="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
 

006 Android XML 文件布局及组件属性设置技巧汇总的更多相关文章

  1. 个人经验 - Android的RelativeLayout布局的layout_height属性设置为wrap_content时的坑

    Android的RelativeLayout布局的layout_height属性设置为wrap_content时的坑: 此坑出现的条件: 1.RelativeLayout布局的layout_heigh ...

  2. Android XML文件布局各个属性详解

    第一常用类:属性值为true或false android:layout_centerHrizontal 水平居中 android:layout_centerVertical 垂直居中 android: ...

  3. Java jdom解析xml文件带冒号的属性

    Java jdom解析xml文件带冒号的属性 转载请标明出处: https://dujinyang.blog.csdn.net/article/details/99644824 本文出自:[奥特曼超人 ...

  4. 《!--suppress ALL --> 在Android XML 文件中的用途是什么?

    <!--suppress ALL --> 在Android XML 文件中的用途是什么? 警告一次又一次地出现在谷歌地图的 XML 文件中,但是当我使用时,所有警告都被禁用.那么压制所有评 ...

  5. Android中TextView和EditView常用属性设置

    Android中TextView和EditView常用属性设置 点击跳转

  6. 004 Android XML文件常用五大页面布局方式

    1.线性布局(LinearLayout)最常用 <1>使用线性布局,首先在xml文件中修改布局为LinearLayout 修改完成后,可在Component Tree中看见如下内容: &l ...

  7. Android中fragment_main.xml文件里的组件获取的问题

    package com.dhy.phonedial; import android.app.Activity; import android.app.Fragment; import android. ...

  8. android xml文件

    一.布局文件:在layout目录下,使用比较广泛: 我们可以为应用定义两套或多套布局,例如:可以新建目录layout_land(代表手机横屏布局),layout_port(代表手机竖屏布局),系统会根 ...

  9. Android 控件布局常用的属性

    <!--单个控件经常用到android:id —— 为控件指定相应的IDandroid:text —— 指定控件当中显示的文字,需要注意的是,这里尽量使用strings.xml文件当中的字符串a ...

随机推荐

  1. 使用GDB调试PHP代码,解决PHP代码死循环

    最近在帮同事解决Swoole Server问题时,发现有1个worker进程一直处于R的状态,而且CPU耗时非常高.初步断定是PHP代码中发生死循环. 下面通过一段代码展示如何解决PHP死循环问题. ...

  2. laravel tinker测试模型添加属性

    php artisan tinker 新建一个模型对象 $post=new \App\Posts(); 给对象的属性挨个赋值 $post->title="this is title&q ...

  3. ArcEngine开发遇到的问题(转)

    ArcEngine开发遇到的问题 https://blog.csdn.net/u013751758/article/category/6971559 转载 2018年02月11日 17:28:11 1 ...

  4. 747. Largest Number At Least Twice of Others比所有数字都大两倍的最大数

    [抄题]: In a given integer array nums, there is always exactly one largest element. Find whether the l ...

  5. Fedora 16下安装ruby on rails

    Fedora 16下安装ruby on rails 最近在windows下写了些rails小程序,问题一个接一个,到最后终于坚信了那句话“windows不适合用于ruby on rails开发”.于是 ...

  6. javascript中把一个数组的内容全部赋值给另外一个数组

    如:var a = [1,2,3,4];var b= [];b = a;这个不是把值赋值过去而是b作为a的引用,b改变的是a如何b指向的是一个新数组,a把元素值全部赋值过去? 1.普通数组可以使用   ...

  7. python 测试报告发送邮件

    使用过程成出现的如下错误 smtplib.SMTPDataError: (554, 'DT:SPM 126 smtp5错误解决办法   1.自动化测试中,调用邮件模块自动发送邮件时,运行脚本报错: s ...

  8. 【转】android 手势识别和VelocityTracker

    参考地址: http://jcodecraeer.com/a/anzhuokaifa/androidkaifa/2012/1020/448.html http://www.jcodecraeer.co ...

  9. C#@的用法

    string path = @"C:\Windows\"; // 如果不加 @,编译会提示无法识别的转义序列 // 如果不加 @,可以写成如下 string path2 = &qu ...

  10. MQ入门总结(一)消息队列概念和使用场景

    一.消息队列 消息即是信息的载体.为了让消息发送者和消息接收者都能够明白消息所承载的信息(消息发送者需要知道如何构造消息:消息接收者需要知道如何解析消息),它们就需要按照一种统一的格式描述消息,这种统 ...