android屏幕居中
㈠ 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 設置textView水平居中顯示
1、讓textView裡面的內容水平居中
設置textView屬性:android:gravity="center_horizontal"
2、讓textView控制項在它的父布局裡水平居中
設置textView屬性:android:layout_gravity="center_horizontal"
(2)android屏幕居中擴展閱讀
android textView的屬性介紹
1、android:autoLink
設置是否當文本為URL鏈接/email/電話號碼/map時,文本顯示為可點擊的鏈接。可選值(none/web/email/phone/map/all)
2、android:autoText
如果設置,將自動執行輸入值的拼寫糾正。此處無效果,在顯示輸入法並輸入的時候起作用。
3、android:bufferType
指定getText()方式取得的文本類別。選項editable類似於StringBuilder可追加字元,也就是說getText後可調用append方法設置文本內容。
4、android:capitalize
設置英文字母大寫類型。此處無效果,需要彈出輸入法才能看得到,參見EditView此屬性說明。
5、android:cursorVisible
設定游標為顯示/隱藏,默認顯示。
㈢ 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();
㈣ 在android中如何讓布局居中
兩種方法:
圖形化設計界面中:選中要居中的組件。在右邊的「屬性欄」(前提是你沒有把它隱藏掉)中的Gravity一欄選擇center_vertical或者center_horizontal或者center。分別表示在父布局中垂直居中、水平居中、中心。
xml代碼界面當中:android:layout_gravity="center_vertical或center_horizontal或center"
㈤ android 怎樣設置title 居中顯示
1在onCreate()方法中加上這三句話:
[java] view plain
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.title);
在布局文件中新建一個title.xml文件:
[java] view plain
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http //schemas android com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<TextView android:id="@+id/textTile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="title" />
</LinearLayout>
㈥ androidstudio設置了水平居中為什麼還望左上角
布局文件中控制項屬性設置有誤,控制項尺寸設置問題,父容器的屬性設置有誤。
1、布局文件中控制項屬性設置有誤:可在設置控制項屬性時設置錯誤。
2、控制項尺寸設置問題:控制項的寬度不是match_parent或wrap_content,而是固定值的話,那麼即使設置了水平居中的屬性,也會顯示在左上角。
3、父容器的屬性設置有誤:控制項所在的父容器的布局屬性設置有誤,也會導致控制項錯誤地顯示在左上角。
另外,可以嘗試在代碼中動態設置控制項的水平方向的充滿或居中等屬性,或者使用 ConstraintLayout 的 GuideLine 來幫助更好地實現水平居中控制項。