Young87

SmartCat's Blog

So happy to code my life!

游戏开发交流QQ群号60398951

当前位置:首页 >跨站数据测试

android studio线性布局,相对布局,TestView

线性布局(LinearLayout)

1.常用属性
常用属性值及作用
android:id关键字的作用
android:layout_widthwrap_content:内容有多少就匹配多少;match_parent:匹配父空间,上一级空间宽度是多少就是多少4;设置数字的时候单位是dp
android:layout_height高度,与上面宽度类似
android:background用6位色彩16进制数字表示
android:layout_margin外边距,该元素距离下一个元素的距离
android:layout_padding内部元素距外部元素的边距
android:orientationhorizontal水平排列;vertical竖直排列
android:gravity加入设置为居中,那么其内部的View块就居中显示
android:layout_weight用于View当中,用于设置权重
2.部分代码如下

注意:如果只有两个View,均设权重为1,某一部分设置了宽度,则在总宽度减去这部分,再平分。

<view
    android:layout_width="50dp"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:layout_weight="1"/>
<view
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:background="#000000"
    android:layout_weight="1"/>

相对布局

1.最常用的属性
常用属性值及作用
android:layout_toLeftOf在某个id的左边
android:layout_toRightOf在某个id的右边
android:layout_alignBottom跟底部对齐
android:layout_alignParentBottom跟父空间底部对齐

TestView

1.用处

1)文字大小、颜色

android:text="你好"
android:textColor="#123456"
android:textSize="24sp"

2)显示不下使用
以下代码显示不下就显示…

android:maxLines="1"
android:ellipsize="end"

3)文字+icon

android:drawableRight="@drawable/图片"
android:drawablePadding="5dp"

4)中划线、下划线

mtv = (TextView) findViewById(R.id.t3);
mtv.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);//中划线
mtv.getPaint().setAntiAlias(true);//去除锯齿

Activity界面,下划线为Paint.underLine_…

补充

1.Alter + enter:弹出提示,可以导入相关包

除特别声明,本站所有文章均为原创,如需转载请以超级链接形式注明出处:SmartCat's Blog

上一篇: 鹅厂程序员在家撸码的十大姿势

下一篇: Java基础知识面试题(2020最新版)

精华推荐