導航:首頁 > 操作系統 > android水平居中垂直居中

android水平居中垂直居中

發布時間:2025-05-25 20:13:49

A. android開發橫豎屏問題

Android橫屏豎屏設置

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//設置成全屏模式

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE););//強制為橫屏
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//豎屏
我做的東西裡面還用到了去掉標題欄。
我也貼出來
requestWindowFeature(Window.FEATURE_NO_TITLE);

垂直居中:

android:layout_centerVertical="true"

水平居中:

android:layout_centerHorizontal="true"

1.hideStatusbarAndTitlebar()隱藏statusbar和titlebar.

private void hideStatusbarAndTitlebar() {
final Window win = getWindow();
// No Statusbar
win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// No Titlebar
requestWindowFeature(Window.FEATURE_NO_TITLE);
}
2.設置屏幕顯示模式ScreenOrientation.

在activity里設置android:screenOrientation的值。
android:screenOrientation的屬性有以下值:
unspecified(默 認值,由系統判斷狀態自動切換),The default value. The system chooses the orientation. The policy it uses, and therefore the choices made in specific contexts, may differ from device to device.
landscape,橫屏
portrait,豎屏
user(用戶當前設置的orientation值),The user's current preferred orientation.
behind(下一個要顯示的Activity的orientation值),The same orientation as the activity that's immediately beneath it in the activity stack.
sensor(傳 感器的方向),The orientation determined by a physical orientation sensor. The orientation of the display depends on how the user is holding the device; it changes when the user rotates the device.
nosensor(不 使用感測器,這個效果差不多等於unspecified).An orientation determined without reference to a physical orientation sensor. The sensor is ignored, so the display will not rotate based on how the user moves the device. Except for this distinction, the system chooses the orientation using the same policy as for the "unspecified" setting.

3.水平/垂直居中的方法.

設置parent的android:gravity為"center"。

4.獲得當前屏幕寬高的方法.

Display display = getWindowManager().getDefaultDisplay();
Config.screenWidth = display.getWidth();
Config.screenHeight = display.getHeight();

B. android:layout_alignParentLeft="true"是什麼意思

該行代碼的總體含義為:
某控制項里有該代碼.某空間相對於父控制項左對齊;

android:layout_alignParentLeft="true"

align為對齊方式; parent為父控制項 left為左;

C. 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是用來顯示字元串的組件,在手機上就是顯示一塊文本的區域。

D. 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>

E. 在android中如何讓布局居中

兩種方法:

  1. 圖形化設計界面中:選中要居中的組件。在右邊的「屬性欄」(前提是你沒有把它隱藏掉)中的Gravity一欄選擇center_vertical或者center_horizontal或者center。分別表示在父布局中垂直居中、水平居中、中心。

  2. xml代碼界面當中:android:layout_gravity="center_vertical或center_horizontal或center"

閱讀全文

與android水平居中垂直居中相關的資料

熱點內容
程序員m1 瀏覽:809
單片機輸出正弦波程序 瀏覽:902
php判斷余數 瀏覽:201
自製微型壓縮機空調 瀏覽:314
太陽違背國王的命令動畫 瀏覽:61
phpdefinedefined 瀏覽:231
編譯原理圖書下載 瀏覽:555
梁鋼筋加密區在哪些地方 瀏覽:355
程序員怎麼清理刪除不掉的軟體 瀏覽:483
畫漫畫用什麼app 瀏覽:530
伺服器在手機怎麼登錄 瀏覽:227
怎麼在wincc上加密碼 瀏覽:124
怎麼判斷自己的門禁卡有沒有加密 瀏覽:43
程序員美食攻略 瀏覽:858
php支付寶rsa加密 瀏覽:404
android水平居中垂直居中 瀏覽:763
java程序員缺口 瀏覽:431
python在哪裝 瀏覽:48
測年齡的app叫什麼 瀏覽:314
網上班會課用什麼app開 瀏覽:931