Android学习笔记(一)----LinearLayout,RelativeLayout,TextView

今天是第一天,想好好的学习Android的开发

(2-1)线性布局(LinearLayout)和相对布局(RelativeLayout)

首先是线性布局LinearLayout:
在这里插入图片描述
android:layout_margin:外边距,当前组件距离其父组件上的边距,指的就是与外部界面的边距
android:layout_padding:内边距,是相对于当前组件而言的,就是指组件内的文本距离当前组件的边距
android:gravity:表示组件的子组件在组件中的位置
android:orientation:方向,有vertical和horizontal
android:layout_weight:权重,占父组件剩余空间的比例(若子组件已设置width和height)在这里插入图片描述
可用于对父组件空间按比例的划分

		<View
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#000000"
            android:layout_weight="1"/>
        <View
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#ff0033"
            android:layout_weight="1"/>

相对布局RelativeLayout:
在这里插入图片描述
android:layout_toLeftOf:相对于某组件的左边
android:layout_alignBotom:将该控件的底部边缘与给定ID的底部边缘对齐
android:layout_below :将该控件的底部置于给定ID的控件之下;

(2-2)TextView:

主要掌握以下操作:
在这里插入图片描述

1.字体设置

layout_width:
① fill_parent
设置一个视图的布局为fill_parent将强制性地使视图扩展至父元素大小。
② match_parent
Android 中match_parent和fill_parent意思一样,但match_parent更贴切,于是从2.2开始两个词都可以
用,但2.3版本后建议使用match_parent。
③ wrap_content
自适应大小,强制性地使视图扩展以便显示其全部内容。以TextView和ImageView控件为例,设置为
wrap_content将完整显示其内部的文本和图像。布局元素将根据内容更改大小。
textSize:单位常用sp

2.显示不下设置

android:ellipsize="end"

其效果如下:
在这里插入图片描述

3.文字+icon

android:drawableRight="@drawable/icon_arrow_off"

在文字右边加入位于drawable文件夹里的图片icon_arrow_off

android:drawablePadding="10dp"

设置边距
其效果如下:
在这里插入图片描述

4.中划线,下划线:

通过java代码来实现
中划线:
mTv4是TextView对象

mTv4 = findViewById(R.id.tv_4);
mTv4.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);//中划线
mTv4.getPaint().setAntiAlias(true);//去除锯齿,用来防止边缘的锯齿

下划线:
mTv5是TextView对象

mTv5 = findViewById(R.id.tv_5);
mTv5.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);//下划线
mTv5.getPaint().setAntiAlias(true);//去除锯齿

也可以通过html方法来实现,但已被弃用,不推荐

mTv6 = findViewById(R.id.tv_6);
mTv6.setText(Html.fromHtml("<u>你好</u>"));

5.跑马灯

实现文字的滚动效果

android:singleLine="true"//设置单行显示(虽已被弃用当有些时候需要用到)
android:ellipsize="marquee"//跑马灯
android:marqueeRepeatLimit="marquee_forever"//一直循环
android:focusable="true"//获取焦点
android:focusableInTouchMode="true"//在进入触摸输入模式后,该控件是否还有获得焦点的能力

下一节Button,不知道会坚持学习多久,继续吧

发布了38 篇原创文章 · 获赞 6 · 访问量 3424

猜你喜欢

转载自blog.csdn.net/qq_37704124/article/details/84110789
今日推荐