文章出處

  • Button
    android:textAllCaps="false" // Button上的英文字符不轉成大寫

  • EditText
    android:maxLines="2" // 指定EditText最大行數為2行,超過2行時文本向上滾動。

  • ImageView
    setImageResource(R.drawable.picture)

  • ProgressBar
    ProgressBar.getProgress()
    ProgressBar.setProgress(int)
    ProgressBar.setMax(int)

  • AlertDialog
    setCancelable(boolean)
    setPositiveButton()
    setNegativeButton()
    show()

  • ProgressDialog
    setCancelable(boolean)
    show()
    繼承自AlertDialog

  • RelativeLayout
    android:layout_centerInParent="true"
    android:layout_alignLeft // 表示讓一個控件的左邊緣和另一個控件的左邊緣對齊

  • PercentFrameLayout
    compile 'com.android.support:percent:25.1.0'

    為了兼容低版本,使用xmlns:app
    app:layout_widthPercent="50%"
    用這個就不用再寫android:layout_width

  • 在布局中引入其他布局文件

    <include layout="@layout/toolbar" />

    這樣使得不必在每個Activity的界面都實現一遍這個布局。

  • padding 和 margin

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">
    
        <Button
            android:id="@+id/btn_test"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="30dp"
            android:padding="50dp"
            android:text="@string/test"/>
    
    </RelativeLayout>

  • Android控件的三個屬性

    屬性 說明
    View.VISIBLE 可見
    VIEW.INVISIBLE 不可見,但占據原來的位置
    VIEW.GONE 完全消失

    setVisibility(從上面三個選)

  • 創建自定義控件

    public class TitleLayout extends LinearLayout { 
    
      public TitleLayout(Context context, AttributeSet attrs) { 
        super(context, attrs); 
        LayoutInflater.from(context).inflate(R.layout.title, this); 
        // 可以在這里注冊布局內按鈕的點擊事件
      } 
    }
    <com.域名.包名.TitleLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

文章列表


不含病毒。www.avast.com
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()