天天看點

猿創征文|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]​

主線程錯誤:你這個是耗時操作,系統認為可能會阻塞程序而報錯。耗時操作還有動畫渲染,音視訊格式轉換等…