當前位置:首頁 » 安卓系統 » android居右

android居右

發布時間: 2023-02-27 09:52:11

A. android:只用線性布局,怎麼實現一行兩個按鈕,一個居中,一個居右,求大俠,求源碼!!

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="horizontal">

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
="true" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_CenterHrizontal="true" />

</LinearLayout>
你的問題差不多就是這樣吧,一個設置水平居中一個就是絕對靠右

B. android中如何設置不規則布局

android 常用布局
1、線性布局 LinearLayout:
線性布局是所有布局中最常用的類之一,也是RadioGroup, TabWidget, TableLayout, TableRow, ZoomControls類的父類。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:layout_height="wrap_content"
>
<!--
android:id —— 為控制項指定相應的ID
android:text —— 指定控制項當中顯示的文字,需要注意的是,這里盡量使用strings.xml文件當中的字元串
android:grivity —— 指定控制項的基本位置,比如說居中,居右等位置
android:textSize —— 指定控制項當中字體的大小
android:background —— 指定該控制項所使用的背景色,RGB命名法
android:width —— 指定控制項的寬度
android:height —— 指定控制項的高度
android:padding* —— 指定控制項的內邊距,也就是說控制項當中的內容
android:layout_weight —— 控制項之間的權重比
android:sigleLine —— 如果設置為真的話,則將控制項的內容在同一行當中進行顯示
-->
<TextView
android:id="@+id/firstText"
android:text="第一行一行一行一行一行一行一行一行一行一行"
android:gravity="center_vertical"
android:textSize="35pt"
android:background="#aa0000"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dip"
android:paddingTop="20dip"
android:paddingRight="30dip"
android:paddingBottom="40dip"
android:layout_weight="1"
android:singleLine="true"/>
<TextView
android:id="@+id/secondText"
android:text="第二行"
android:gravity="center_vertical"
android:textSize="15pt"
android:background="#0000aa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
2、相對布局 RelativeLayout
相對布局 RelativeLayout 允許子元素指定它們相對於其父元素或兄弟元素的位置,這是實際布局中最常用的布局方式之一。它靈活性大很多,當然屬性也多,操作難度也大,屬性之間產生沖突的的可能性也大,使用相對布局時要多做些測試。
舉個例子:
<?xml version="1.0" encoding="utf-8"?>
<!--
android:layout_above 將該控制項的底部至於給定ID的控制項之上
android:layout_below 將該控制項的頂部至於給定ID的控制項之下
android:layout_toLeftOf 將該控制項的右邊緣和給定ID的控制項的左邊緣對齊
android:layout_toRightOf 將該控制項的左邊緣和給定ID的控制項的右邊緣對齊
android:layout_alignBaseline 該控制項的baseline和給定ID的控制項的baseline對齊
android:layout_alignBottom 將該控制項的底部邊緣與給定ID控制項的底部邊緣
android:layout_alignLeft 將該控制項的左邊緣與給定ID控制項的左邊緣對齊
android:layout_alignRight 將該控制項的右邊緣與給定ID控制項的右邊緣對齊
android:layout_alignTop 將給定控制項的頂部邊緣與給定ID控制項的頂部對齊

android:alignParentBottom 如果該值為true,則將該控制項的底部和父控制項的底部對齊
android:layout_alignParentLeft 如果該值為true,則將該控制項的左邊與父控制項的左邊對齊
android:layout_alignParentRight 如果該值為true,則將該控制項的右邊與父控制項的右邊對齊
android:layout_alignParentTop 如果該值為true,則將空間的頂部與父控制項的頂部對齊
android:layout_centerHorizontal 如果值為真,該控制項將被至於水平方向的中央
android:layout_centerInParent 如果值為真,該控制項將被至於父控制項水平方向和垂直方向的中央
android:layout_centerVertical 如果值為真,該控制項將被至於垂直方向的中央
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Type here:" />
<EditText
android:id="@+id/entry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/label" />
<Button android:id="@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/entry"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="OK" />
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/ok"
android:layout_alignTop="@id/ok"
android:text="Cancel" />
</RelativeLayout>
3、表單布局 TableLayout
和TableRow配合使用,和HTML里的Table相似。
舉個例子:
<?xml version="1.0" encoding="utf-8" ?>
- <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="1">
- <TableRow>
<TextView android:layout_column="1" android:text="打開..." android:padding="3dip" />
<TextView android:text="Ctrl-O" android:gravity="right" android:padding="3dip" />
</TableRow>
- <TableRow>
<TextView android:layout_column="1" android:text="保存..." android:padding="3dip" />
<TextView android:text="Ctrl-S" android:gravity="right" android:padding="3dip" />
</TableRow>
- <TableRow>
<TextView android:layout_column="1" android:text="另存為..." android:padding="3dip" />
<TextView android:text="Ctrl-Shift-S" android:gravity="right" android:padding="3dip" />
</TableRow>
<View android:layout_height="2dip" android:background="#FF909090" />
- <TableRow>
<TextView android:text="*" android:padding="3dip" />
<TextView android:text="導入..." android:padding="3dip" />
</TableRow>
- <TableRow>
<TextView android:text="*" android:padding="3dip" />
<TextView android:text="導出..." android:padding="3dip" />
<TextView android:text="Ctrl-E" android:gravity="right" android:padding="3dip" />
</TableRow>
<View android:layout_height="2dip" android:background="#FF909090" />
- <TableRow>
<TextView android:layout_column="1" android:text="退出" android:padding="3dip" />
</TableRow>
</TableLayout>
4、切換卡 Tabwidget
繼承TabActivity,實現標簽的切換功能。
舉個例子:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/textview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a tab" />
<TextView
android:id="@+id/textview2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is another tab" />
<TextView
android:id="@+id/textview3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a third tab" />
</FrameLayout>
</LinearLayout>
</TabHost>
其他布局:
1、幀布局 FrameLayout:
是最簡單的一個布局對象。在他裡面的的所有顯示對象愛你過都將固定在屏幕的左上角,不能指定位置,但允許有多個顯示對象,只是後一個會直接覆蓋在前一個之上顯示,會把前面的組件部分或全部擋住。
舉個例子:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:text="big"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="50pt"/>
<TextView
android:text="middle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20pt"/>
<TextView
android:text="small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10pt"/>
</FrameLayout>
2、絕對布局 AbsoluteLayout
絕對定位AbsoluteLayout,又可以叫做坐標布局,可以直接指定子元素的絕對位置,這種布局簡單直接,直觀性強,但是由於手機屏幕尺寸差別比較大,使用絕對定位的適應性會比較差。解析度不一樣的屏幕,顯示的位置也會有所不同。
舉個例子:
< ?xml version="1.0" encoding="utf-8"?>
< AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
< EditText
android:text="Welcome to Mr Wei's blog"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
< Button
android:layout_x="250px" //設置按鈕的X坐標
android:layout_y="40px" //設置按鈕的Y坐標
android:layout_width="70px" //設置按鈕的寬度
android:layout_height="wrap_content"
android:text="Button"/>
< /AbsoluteLayout>

C. android 線性布局 居右

線性布局默認是水平的,orientation的屬性效果就是確定LinearLayout是縱線還是橫線。就問題而言,一個控制項在橫線上在左邊還是右邊可以設置,但若是兩個控制項就不行了。若是可以的話,那讓RelativeLayout情何以堪...

D. Android布局文件中有兩個控制項,當顯示一個控制項的時候另一個居右,顯示兩個的時候兩個並排居右,怎麼做

首先可以先將介紹這個TextView創建好並隱藏起來,然後在代碼中判斷什麼時候顯示就好。
顯示時用textView.setVisibility(View.VISIBLE);隱藏時用textView.setVisibility(View.GONE);

E. android v7包里的Toolbar,怎麼定製圖標,字體居中的效果

1.文字的話僅可設置為底部居中或中部居右,在TextAlignment屬性中設置,值分別為0和1,沒有中部居中,至於為什麼在下面說明了; 2.不能改字體,不能改顏色。 另外,強烈建議用Toolbar工具欄設計時使用圖標來代替文字,或者圖標和文字都有,相信用過Windows我的電腦工具欄自定義的都知道,標簽可選為「顯示文本標簽」(就是顯示在圖標下面)或「選擇性地文本置於右側」這就是第1點為什麼只能選2個值的原因了。 至於怎麼用圖標,再拖一個ImageList控制項進窗體,設計時插入所有要用到的圖標,記住每個圖標的索引編號,在Toolbar控制項中設置按鈕圖像為索引編號,0為沒有圖標。 編程時實現採用 Toolbar1.Buttons(1).Image = 索引

熱點內容
idle運行python文件 發布:2025-05-15 17:12:19 瀏覽:231
主存儲器屬於外存儲器嗎 發布:2025-05-15 16:54:00 瀏覽:755
顯示屏看股票都有哪些配置 發布:2025-05-15 16:52:39 瀏覽:397
android行情 發布:2025-05-15 16:52:25 瀏覽:438
活動上線前伺服器配置要注意什麼 發布:2025-05-15 16:38:43 瀏覽:949
王者榮耀安卓區怎麼免費轉蘋果 發布:2025-05-15 16:18:02 瀏覽:763
威朗pro高配都有哪些配置 發布:2025-05-15 15:57:09 瀏覽:958
資料庫分頁查詢數據 發布:2025-05-15 15:45:13 瀏覽:522
phpmyadmin上傳限制 發布:2025-05-15 15:39:52 瀏覽:432
如何給手機配置真正的電腦 發布:2025-05-15 15:39:52 瀏覽:765