Ⅰ android如何實現textview水平垂直居中
1、方法:設置textview的屬性android:layout_gravity="center"
2、補充:
(1)android:layout_gravity:View組件相對於Container的對齊方式。center表示將對象橫縱居中,不改變其大小。
(2)屬性可選的值還有:top、bottom、left、right、center_vertical、fill_vertical、center_horizontal、fill_horizontal、fill、clip_vertical。
3、android
(1)Android是一種基於Linux的自由及開放源代碼的操謹慧作系統,主要使用於祥粗答移動設備,如智能手機和平板電腦,由Google公司和開放手機聯盟領導及開發。尚未有統一中文名稱,中國大陸地區較多人使用「安卓」或「安致」。Android操凳猜作系統最初由Andy Rubin開發,主要支持手機。2005年8月由Google收購注資。
(2)2007年11月,Google與84家硬體製造商、軟體開發商及電信營運商組建開放手機聯盟共同研發改良Android系統。隨後Google以Apache開源許可證的授權方式,發布了Android的源代碼。第一部Android智能手機發布於2008年10月。Android逐漸擴展到平板電腦及其他領域上,如電視、數碼相機、游戲機等。2011年第一季度,Android在全球的市場份額首次超過塞班系統,躍居全球第一。
4、textview:textView是用來顯示字元串的組件,在手機上就是顯示一塊文本的區域。
Ⅱ android:gravity="center_vertical"
android:gravity="center_vertical" 這個的意思是指 限定它裡面的內容要垂直居中顯示。
android:layout_gravity="center_vertical",這個是指它的位置是相對於它父親的垂直居中。
比如:
//第一種:裡面的內容都要垂直居中顯示,是由父類限定子控制項的位置,每個子控制項都要滿足這個條件。
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical" //這個指裡面的子內容要垂直居中顯示
>
<TextView 這個 就會垂直居中顯示
android:layout_width="wrap_context"
android:layout_height="wrap_context"/>
/>
</LinearLayout>
//第二種:是子控制項自己去排位置,每個控制項可以設置不同的
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="wrap_context"
android:layout_height="wrap_context"
android:layout_gravity="center_vertical" //這個就是讓他相對於父親的垂直中間顯示。
/>
</LinearLayout>