天天看点

猿创征文|Android常用知识总结

猿创征文|Android常用知识总结
android:gravity="center_horizontal|bottom"
android:layout_weight="0.5"      

🚀🚀《wrap_content和match_parent的区别 ? 》

🍓   wrap_content 控件内容决定大小。
🍓   match_parent直接占满剩余空间,与控件内容多少没有关系。      

wrap_content:表示控件宽/高度可由内容来决定。对于TextView,文字越长,它的宽度越宽,直到父view(上层容器)允许的最大宽/高度。

match_parent:表示控件宽/高度达到父view允许的最大值。通俗说就是把空间撑满。

🚀🚀dp 和 sp 的区别

🍓🍓 dp和sp使用产生的效果没有什么区别,但是sp作为字体大小单位时,字体会随着系统的字体大小改变。dp作为字体大小单位时,字体不会随着系统字体变化。

🚀🚀《margin 和 padding有什么区别 ?》

🍓 margin设置组件与父容器的边距 layout_marginLeft layout_marginBottom

🍓 设置组件( 父容器 )内部元素的边距

​都是边距,不过padding是父容器和外部边距,margin是子容器之间,子容器和父容器之间的距离​

TableRow 可以把两个三个乃至更多的Button按钮放在一行,但是Button多了,不换行,超出的无法显示。

隐藏: android:collapseColumns="1,3"隐藏索引为1和3的按钮

拉伸: android:stretchColumns=“0” 拉伸索引为0的按钮 注意:索引为 “隐藏的按钮”拉伸不显示效果。

收缩: android:shrinkColumns=“1” 收缩索引为1的按钮,也就是第二个按钮。 注意:必须按钮布局超出页面才有效果。

换位: android:layout_column=“2” 换位,当前位置换位索引为2的位置,后面的按顺序排列。

跨度: android:layout_span=“2” 跨度为2 ,一个按钮的长度和之前两个按钮的长度一致

🍟🍟 一行三列

android:orientation=“horizontal”

android:columnCount=“3”

🍗🍗 一列三行

android:orientation=“vertical”

android:rowCount=“3”

android:layout_columnWeight=“1” 行抢占

android:layout_rowWeight=“1” 列抢占

🦪🦪🦪🦪 六大布局 🦪🦪🦪🦪

Android六大基本布局分别是:

线性布局:LinearLayout

表格布局:TableLayout

相对布局:RelativeLayout

层布局:FrameLayout

绝对布局:AbsoluteLayout

网格布局:GridLayout

🚀🚀《《 表格布局,TableLayout的基本使用方式 》》

🍿🍿1、TableLayout(表格布局)的样式,就像是一张表格。每个TableLayout,都由多个TableRow组成,每个

TableRow就是一行,有几个TableRow就有几行。TableLayout不会显示行号和列号,也没有分割线,其行

数和列数都可以进行操作。

🍿🍿2、TableLayout的android:shrinkColumns属性,当TableRow里边的空间布满布局的时候,指定列自动延

伸以填充可用部分。当TableRow里边的控件还没有布满布局时,android:shrinkColumns不起作用。

🍿🍿3-1、TableLayout的android:stretchColumns属性,用于指定列对空白部分进行填充。

🍿🍿3-2、android:stretchColumns属性,若有多列需要设置为可伸展,请用逗号将需要伸展的列序号隔开。

🍿🍿4、TableLayout的android:collapseColumns属性,用于隐藏指定的列,若有多列需要隐藏,请用逗号将需

要隐藏的列序号隔开。

🍿🍿5、TableLayout的android:layout_span属性,设置组件显示所占用的列数。

🍿🍿6、TableLayout的android:layout_column属性,设置组件所在列数。

top

start

end

bottom

猿创征文|Android常用知识总结

🚀🚀《 MainActivity.this 和 this 的区别 》

🍵🍵 this是当前类的对象,MainActivity.this指的的MainActivity的一个对象,当你就在MainActivity里操作的时候,

这两者没啥区别一样的,但是如果你是在MainActivity这里类的匿名类里操作,那就不一样了。比如你在

MainActivity里有一个button,在button的setOnClickListener()里面用this指的就是这个消息响应类而

不是MainActivity了。

🚀🚀《《 backgroundTint和background有什么区别 》》

🍟🍟自然就是,如果你只是要给背景上纯色的话,建议用backgroundTint,如果你要用背景图片的话,

就用background,可以分别提高对应的执行效率!!!

🚀🚀visibility 三个属性值

🍳🍳🍳🍳🍳

visibility visible 可见

invisible 不可见,占位置

gone 不可见,不占位置

​image这个绑定的id控件设置为可见​

password.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                imageView.setVisibility(View.VISIBLE);
            }
        });      

🚀🚀今日份bug

​页面跳转不成功​

跳转的页面需要在AndroidManifest.xml中注册,

例如

注册NotificationActivity界面

​Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.View$OnUnhandledKeyEventListener" on path: DexPathList[[zip file "/data/app/com.example.listview-2/base.apk"],nativeLibraryDirectories=[/data/app/com.e xample.listview-2/lib/x86, /system/lib, /vendor/lib]​

主线程错误:你这个是耗时操作,系统认为可能会阻塞进程而报错。耗时操作还有动画渲染,音视频格式转换等…