android編程中的瑣碎知識點匯總(2)

來源:互聯網
上載者:User

1.控制項配置 xml中有趣的屬性:
android:background
可以通過以下兩種方法設定背景為透明:"@android:color/transparent"和"@null"。注意TextView預設是透明的,不用寫此屬性,但是Buttom/ImageButton/ImageView想透明的話就得寫這個屬性了。
android:drawingCacheQuality
設定繪圖時半透明品質。有以下值可設定:auto(預設,由架構決定)/high(高品質,使用較高的色彩深度,消耗更多的記憶體/low(低品質,使用較低的色彩深度,但是用更少的記憶體)。
android:fadingEdge
設定拉捲軸時 ,邊框漸層的放向。none(邊框顏色不變),horizontal(水平方向顏色變淡),vertical(垂直方向顏色變淡)。
android:fadingEdgeLength
設定邊框漸層的長度。
android:scrollbarDefaultDelayBeforeFade
設定N毫秒後開始淡化,以毫秒為單位。
android:scrollbarFadeDuration
設定捲軸淡出效果(從有到慢慢的變淡直至消失)時間,以毫秒為單位。Android2.2中捲軸滾動完之後會消失,再滾動又會出來,在1.5、1.6版本裡面會一直顯示著。
android:scrollbarThumbHorizontal
設定水平捲軸的drawable。
android:scrollbarThumbVertical
設定垂直捲軸的drawable.
android:scrollbarTrackHorizontal
設定水平捲軸背景(軌跡)的色drawable
android:scrollbarTrackVertical
設 置垂直捲軸背景(軌跡)的drawable注意直接設定顏色值如”android:color/white”將得出很難看的效果,甚至都不理解這個屬性 了,這裡可以參見ApiDemos裡res/drawable/scrollbar_vertical_thumb.xml和 scrollbar_vertical_track.xml,設定代碼為:android:scrollbarTrackVertical ="@drawable/scrollbar_vertical_track"
android:soundEffectsEnabled
設定點擊或觸摸時是否有聲音效果
android:visibility
設定是否顯示View。設定值:visible(預設值,顯示),invisible(不顯示,但是仍然佔用空間),gone(不顯示,不佔用空間)

 

2.很經典的一個layout.xml

Xml代碼  
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical" android:layout_width="fill_parent"  
  4.     android:padding="8px" android:background="@color/lightblue"  
  5.     android:layout_height="fill_parent" android:gravity="center_horizontal">  
  6.     <LinearLayout android:orientation="vertical"  
  7.         android:layout_width="fill_parent" android:layout_height="wrap_content">  
  8.         <TextView android:text="@string/qr_main_contents"  
  9.             android:textColor="@color/black" android:layout_width="wrap_content"  
  10.             android:layout_height="wrap_content" />  
  11.         <Spinner android:id="@+id/qr_main_contents"  
  12.             android:layout_width="wrap_content" android:layout_height="wrap_content"  
  13.             android:entries="@+array/qr_main_contents" android:prompt="@string/qr_main_contents" />  
  14.     </LinearLayout>  
  15.     <LinearLayout android:layout_width="fill_parent"  
  16.         android:layout_weight="1" android:layout_height="wrap_content"  
  17.         android:scrollbars="vertical">  
  18.         <ScrollView android:layout_width="fill_parent"  
  19.             android:layout_height="fill_parent">  
  20.             <LinearLayout android:layout_width="fill_parent"  
  21.                 android:layout_height="wrap_content" android:orientation="vertical">  
  22.                 <TextView android:text="@string/qr_information_name"  
  23.                     android:textColor="@color/black" android:layout_width="wrap_content"  
  24.                     android:layout_height="wrap_content" />  
  25.                 <EditText android:id="@+id/qr_information_name"  
  26.                     android:textColorHint="@color/blue" android:singleLine="true"  
  27.                     android:layout_width="fill_parent" android:layout_height="wrap_content" />  
  28.                 <TextView android:text="@string/qr_information_company"  
  29.                     android:textColor="@color/black" android:layout_width="wrap_content"  
  30.                     android:layout_height="wrap_content" />  
  31.                 <EditText android:id="@+id/qr_information_company"  
  32.                     android:singleLine="true" android:layout_width="fill_parent"  
  33.                     android:layout_height="wrap_content" />  
  34.                 <TextView android:text="@string/qr_information_phone"  
  35.                     android:textColor="@color/black" android:layout_width="wrap_content"  
  36.                     android:layout_height="wrap_content" />  
  37.                 <EditText android:id="@+id/qr_information_phone"  
  38.                     android:singleLine="true" android:layout_width="fill_parent"  
  39.                     android:layout_height="wrap_content" />  
  40.                 <TextView android:text="@string/qr_information_email"  
  41.                     android:textColor="@color/black" android:layout_width="wrap_content"  
  42.                     android:layout_height="wrap_content" />  
  43.                 <EditText android:id="@+id/qr_information_email"  
  44.                     android:singleLine="true" android:layout_width="fill_parent"  
  45.                     android:layout_height="wrap_content" />  
  46.             </LinearLayout>  
  47.         </ScrollView>  
  48.     </LinearLayout>  
  49.     <LinearLayout android:orientation="vertical"  
  50.         android:gravity="right" android:layout_width="fill_parent"  
  51.         android:layout_height="wrap_content">  
  52.         <Button android:text="@string/qr_main_generate"  
  53.             android:layout_width="wrap_content" android:layout_height="wrap_content" />  
  54.     </LinearLayout>  
  55. </LinearLayout>  

 

 

3.去掉頁面的標題列和資訊列
this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉標題列
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);//去掉資訊列

注意,這個設定必須放在設定布局前面,不然會報錯.
setContentView(R.layout.entrancebs);

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.