android开发小知识2

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 >   
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical" android:layout_width="fill_parent"
	android:padding="8px" android:background="@color/lightblue"
	android:layout_height="fill_parent" android:gravity="center_horizontal">
	<LinearLayout android:orientation="vertical"
		android:layout_width="fill_parent" android:layout_height="wrap_content">
		<TextView android:text="@string/qr_main_contents"
			android:textColor="@color/black" android:layout_width="wrap_content"
			android:layout_height="wrap_content" />
		<Spinner android:id="@+id/qr_main_contents"
			android:layout_width="wrap_content" android:layout_height="wrap_content"
			android:entries="@+array/qr_main_contents" android:prompt="@string/qr_main_contents" />
	</LinearLayout>
	<LinearLayout android:layout_width="fill_parent"
		android:layout_weight="1" android:layout_height="wrap_content"
		android:scrollbars="vertical">
		<ScrollView android:layout_width="fill_parent"
			android:layout_height="fill_parent">
			<LinearLayout android:layout_width="fill_parent"
				android:layout_height="wrap_content" android:orientation="vertical">
				<TextView android:text="@string/qr_information_name"
					android:textColor="@color/black" android:layout_width="wrap_content"
					android:layout_height="wrap_content" />
				<EditText android:id="@+id/qr_information_name"
					android:textColorHint="@color/blue" android:singleLine="true"
					android:layout_width="fill_parent" android:layout_height="wrap_content" />
				<TextView android:text="@string/qr_information_company"
					android:textColor="@color/black" android:layout_width="wrap_content"
					android:layout_height="wrap_content" />
				<EditText android:id="@+id/qr_information_company"
					android:singleLine="true" android:layout_width="fill_parent"
					android:layout_height="wrap_content" />
				<TextView android:text="@string/qr_information_phone"
					android:textColor="@color/black" android:layout_width="wrap_content"
					android:layout_height="wrap_content" />
				<EditText android:id="@+id/qr_information_phone"
					android:singleLine="true" android:layout_width="fill_parent"
					android:layout_height="wrap_content" />
				<TextView android:text="@string/qr_information_email"
					android:textColor="@color/black" android:layout_width="wrap_content"
					android:layout_height="wrap_content" />
				<EditText android:id="@+id/qr_information_email"
					android:singleLine="true" android:layout_width="fill_parent"
					android:layout_height="wrap_content" />
			</LinearLayout>
		</ScrollView>
	</LinearLayout>
	<LinearLayout android:orientation="vertical"
		android:gravity="right" android:layout_width="fill_parent"
		android:layout_height="wrap_content">
		<Button android:text="@string/qr_main_generate"
			android:layout_width="wrap_content" android:layout_height="wrap_content" />
	</LinearLayout>
</LinearLayout>

 

 

3.去掉页面的标题栏和信息栏
this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);//去掉信息栏

注意,这个设置必须放在设置布局前面,不然会报错.
setContentView(R.layout.entrancebs);

你可能感兴趣的:(框架,android,xml)