android左對齊
1. 誰能給我一個關於Android中LineLayout的詳細講解
Android中LinearLayout是線性布局控制項,它包含的子控制項將以橫向或豎向的方式排列,按照相對位置來排列所有的widgets或者其他的containers,超過邊界時,某些控制項將缺失或消失。因此一個垂直列表的每一行只會有一個widget或者是container,而不管他們有多寬,而一個水平列表將會只有一個行高(高度為最高子控制項的高度加上邊框高度)。LinearLayout保持其所包含的widget或者是container之間的間隔以及互相對齊(相對一個控制項的右對齊、中間對齊或者左對齊)。
1.xml屬性
android:baselineAligned:是否允許用戶調整它內容的基線。
android:baselineAlignedChildIndex:當一個線性布局與另一個布局是按基線對齊的一部分,它可以指定其內容的基線對齊方式。
android:gravity:指定如何在該對象中放置此對象的內容(x/y坐標值)。
android:orientation:設置它內容的對其方向(橫向/豎向)。
2.在LinearLayout中設置排列方式為水平時只有垂直方向的設置是有效的,水平方向的設置是無效的:即left,right,center_horizontal 是不生效的
3.在LinearLayout中設置排列方式為垂直時只有水平方向設置是有效的,垂直方向的設置是無效的是無效的:即top,bottom,center_vertical 是無效的
2. android的TextView里的內容怎麼左對齊
默認狀態就是左對齊。也可以在配置文件里加個屬性android:gravity="left"
3. 一個水平的LinearLayout中 有2個控制項,如何讓左邊的空間 左對齊 右邊的控制項右對齊
用相對布局RelativeLayout吧,實現這個效果適合用相對布局
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center_vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:onClick="onBack"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"/>
</RelativeLayout>
4. ios和安卓的區別
1. 應用的設備不同:
IOS和安卓最大的區別在於本身所應用的設備不同。IOS系統主要是應用在iPhone、IPad、itouch設備上的操作系統,安卓系統主要是應用在安卓智能手機上的操作系統。
2. 面向人群不同:
IOS系統面向的是中高層收入的人群,有人稱它為「高富帥」系統,而安卓系統則是面試中低層的大眾人群,有人稱它為「屌絲系統」。
3.系統的開放性區別:
安卓擁有自己的開源計劃AOSP(Android Open Source Project),只要遵循GPL和Apache Licence 2.0開源協議,那麼你就可以使用安卓源代碼進行二次開發。而安卓由於源代碼開放,自然可玩性也比iOS高。此外,安卓比iOS開放了更多的應用介面API,可以很自然地利用安卓實現很多在iOS上不折騰就沒法做的功能。在安卓,可以隨心隨意地更換輸入法,隨意用任何瀏覽器打開鏈接,隨意從任何途經安裝程序,隨意調用第三方程序分享文件——這些在iOS上不越獄都做不到,即使越獄也未必比安卓做得更好。
4. 系統的安全性區別:
IOS系統是一款比較強大的操作系統,在IOS系統運行的程序不管程序多大都不會造成死機,玩起來非常的流程,而且系統的安全性比較高。
安卓系統是屬於代碼系統,如果所有的應用程序需要下載下來之後才能玩,系統用久之後會經常出現卡機或者是死機的現象,而且安卓系統還存在惡意的插件在系統上自動運行,系統漏洞多,導致個人資料被盜、系統耗電大,流量消耗大等,系統安全性相對來說比較低。
5. 開發難度不同:
蘋果提供完整高效xcode,sdk等開發環境,ios系統一脈相承,ios版本之間的軟體通用,即開發一款產品蘋果所有設備都能運行。其硬體的強大也讓開發變的更加容易。
5. android的TextView里的內容怎麼左對齊
TextView里有個屬性可以設置的!方法有兩個:
在xml中設置屬性android:gravity="start";
在代碼中這樣寫 TextView.setGravity(START);
6. android代碼如何快速對齊
1,android:orientation
布局方向。horizontal是讓所有的子元素按水平方向從左到右排列,
vertical是讓所有的子元素按豎直方向從上到下排列。
2,android:gravity 與
android:layout_gravity的區別android:gravity是指定本元素的子元素相對它的對齊方式。
android:layout_gravity是指定本元素相對它的父元素的對齊方式。
例如:
下面這里的linearlayout的android:gravity設為right,有兩個子元素Button01和Button02。
java代碼:
<?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=」fill_parent」
android:gravity=」right」
>
<Button android:text=」button01″ android:id=」@+id/Button01″ android:layout_width=」wrap_content」 android:layout_height=」wrap_content」></Button>
<Button android:text=」button02″ android:id=」@+id/Button02″ android:layout_width=」wrap_content」 android:layout_height=」wrap_content」></Button>
</LinearLayout>
這個main.xml里的LinearLayout也是有兩個子元素Button01和Button02。Button01的android:layout_gravity設為」left」,Button02的
android:layout_gravity設為」right」
java代碼:
<?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=」fill_parent」
>
<Button
android:layout_gravity=」left」
android:text=」button01″
android:id=」@+id/Button01″
android:layout_width=」wrap_content」 a
ndroid:layout_height=」wrap_content」></Button>
<Button
android:layout_gravity=」right」
android:text=」button02″
android:id=」@+id/Button02″
android:layout_width=」wrap_content」
android:layout_height=」wrap_content」>
</Button>
</LinearLayout>
FameLayout布局
FrameLayout是最簡單的一個布局對象。它被定製為你屏幕上的一個空白備用區域,之後你可以在其中填充一個單一對象—比如,一張你要發布的圖片。所有的子元素將會固定在屏幕的左上角;你不能為FrameLayout中的一個子元素指定一個位置。後一個子元素將會直接在前一個子元素之上進行覆蓋填充,把它們部份或全部擋住(除非後
一個子元素是透明的)。xml屬性
1,用xml文件來定義界面,然後Activity的setContentView方法根據xml文件里的定義來創建真正的控制項對象。好比說xml文件是設計圖紙,setContentView是生產機器,它依照圖紙生產出各種各樣的杯具和洗具。
2,FrameLayout的xml屬性來自三個地方:繼承下來的,嵌套類定義的,自身類定義的。
3,具的屬性可查閱官方文檔。下面是剛才遇到的幾個屬性。
java代碼:
android:id
//這個xml屬性是繼承自android.view類的xml屬性。它為framelayout提供一個唯一識別符號,之後,程序要用到它時可以用View.findViewById() 或Activity.findViewById()來找到它。
android:layout_width: 布局寬
android:layout_height: 布局高
//它們的取值是fill_parent或wrap_content。
fill_parent :在x軸或則y軸上充滿父容器的空間。
wrap_content :framelayout里的元素有多少寬高就多少寬高,
//這兩個屬性都是定義在android.widget.FrameLayout的嵌套類android.widget.FrameLayout.LayoutParams里。
android:background:背景
android:foreground :前景
7. android textview 怎麼實現跨行左對
沒明白你意思。。左對齊?你現在不就是左對齊的么?
還是說你要內容部分左邊對齊 意思是後面的行數開始都要在「:」後面對齊?要這樣你就分兩個TextView就好了啊 一個顯示標題 標題右邊一個TextView顯示內容就可以了。。
如果不是這個意思那默認應該就是坐對齊的,,你要是不放心可以gravity設為left
或者說你現在要實現圖片的效果而無法實現? 那你就用一個TextView
然後String title;String content;
SpanableString ss=new SpanableString(title+「:」+content);
ss.setSpan(new ForegroundColorSpan(Color.BLUE),0,title.length(),Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(ss);
8. android的TextView里的內容怎麼左對齊
這樣么
9. android自定義對話框寬不能占滿父layout的解決辦法有哪些
1.FrameLayout
FrameLayout 是 最簡單的一個布局對象。它被定製為你屏幕上的一個空白備用區域,之後你可以在其中填充一個單一對象 —
比如,一張你要發布的圖片。所有的子元素將會固定
在屏幕的左上角;你不能為FrameLayout中的一個子元素指定一個位置。後一個子元素將會直接在前一個子元素之上進行覆蓋填充,把它們部份或全部擋
住(除非後一個子元素是透明的)。
FrameLayout is the simplest type of layout object. It's basically a blank
space on your screen that you can later fill with a single object — for example,
a picture that you'll swap in and out. All child elements of the FrameLayout are
pinned to the top left corner of the screen; you cannot specify a different
location for a child view. Subsequent child views will simply be drawn over
previous ones, partially or totally obscuring them (unless the newer object is
transparent).
FrameLayout默認填充widget等在左上角,然後後面的控制項遮住前面的,比如說有兩個TextView,Text內容分別是I am
textview 1 和
I am textview 2 看到的效果會如下:?xml version="1.0" encoding="utf-8"?>
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="I am textview 1"
/>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="I am textview 2"
/>
2.LinearLayout
LinearLayout
以你為它設置的垂直或水平的屬性值,來排列所有的子元素。所有的子元素都被堆放在其它元素之後,因此一個垂直列表的每一行只會有一個元素,而不管他們有多
寬,而一個水平列表將會只有一個行高(高度為最高子元素的高度加上邊框高度)。LinearLayout保持子元素之間的間隔以及互相對齊(相對一個元素
的右對齊、中間對齊或者左對齊)。
LinearLayout
還支持為單獨的子元素指定weight。好處就是允許子元素可以填充屏幕上的剩餘空間。這也避免了在一個大屏幕中,一串小對象擠成一堆的情況,而是允許他們放大填充空白。子元素指定一個weight值,剩餘的空間就會按這些子元素指定的weight比例分配給這些子元素。默認的weight值為0。例如,如
果有三個文本框,其中兩個指定了weight值為1,那麼,這兩個文本框將等比例地放大,並填滿剩餘的空間,而第三個文本框不會放大。
下 面的兩個窗體採用LinearLayout,包含一組的元素:一個按鈕,幾個標簽,幾個文本框。兩個窗體都為布局做了一番修飾。文本框的width被設置
為FILL_PARENT;其它元素的width被設置為WRAP_CONTENT。默認的對齊方式為左對齊。左邊的窗體沒有設置weight(默認為
0);右邊的窗體的comments文本框weight被設置為1。如果Name文本框也被設置為1,那麼Name和Comments這兩個文本框將會有同樣的高度。
在 一個水平排列的LinearLayout中,各項按他們的文本基線進行排列(第一列第一行的元素,即最上或最左,被設定為參考基線)。因此,人們在一個窗
體中檢索元素時,就不需要七上八下地讀元素的文本了。我們可以在layout的XML中設置
android:baselineAligned="false",來關閉這個設置。
LinearLayout aligns all children in a single direction — vertically or
horizontally, depending on how you define the orientation attribute. All
children are stacked one after the other, so a vertical list will only have one
child per row, no matter how wide they are, and a horizontal list will only be
one row high (the height of the tallest child, plus padding). A LinearLayout
respects margins between children and the gravity(right, center, or left
alignment) of each child.
LinearLayout是Android
sdk創建project時的默認Layout,支持兩種方式,默認是垂直vertical的線性layout,另一個是水平horizontal方向的線性排列。
效果如下android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="I am textview 1"
/>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="I am textview 2"
/>android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:layout_width="10px"
android:layout_height="fill_parent"
android:text="I am textview 1"
/>
android:layout_width="10px"
android:layout_height="wrap_content"
android:text="I am textview 2"
/>
3.RelativeLayout
RelativeLayout 允
許子元素指定他們相對於其它元素或父元素的位置(通過ID指定)。因此,你可以以右對齊,或上下,或置於屏幕中央的形式來排列兩個元素。元素按順序排列,
因此如果第一個元素在屏幕的中央,那麼相對於這個元素的其它元素將以屏幕中央的相對位置來排列。如果使用XML來指定這個layout,在你定義它之前,
被關聯的元素必須定義。
這是一個RelativeLayout例子,其中有可視的和不可視的元素。基礎的屏幕layout對象是一個RelativeLayout對象。
這 個視圖顯示了屏幕元素的類名稱,下面是每個元素的屬性列表。這些屬性一部份是由元素直接提供,另一部份是由容器的LayoutParams成員
(RelativeLayout的子類)提供。RelativeLayout參數有
width,height,below,alignTop,toLeft,padding和marginLeft。注意,這些參數中的一部份,其值是相對
於其它子元素而言的,所以才RelativeLayout。這些參數包括toLeft,alignTop和below,用來指定相對於其它元素的左,上和
下的位置。
RelativeLayout lets child views specify their position relative to the
parent view or to each other (specified by ID). So you can align two elements by
right border, or make one below another, centered in the screen, centered left,
and so on. Elements are rendered in the order given, so if the first element is
centered in the screen, other elements aligning themselves to that element will
be aligned relative to screen center. Also, because of this ordering, if using
XML to specify this layout, the element that you will reference (in order to
position other view objects) must be listed in the XML file before you refer to
it from the other views via its reference ID.android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding = "10px"
>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="I am textview 1"
/>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="I am textview 2"
android:layout_marginLeft = "150px"
/>
android:id="@+id/Button02" android:layout_width="wrap_content"
android:text="Ok"
android:layout_height="wrap_content"
android:layout_marginLeft = "240px"
android:layout_marginTop = "40px"
>
android:layout_marginLeft = "160px"
android:layout_marginTop = "40px"
>
4.AbsoluteLayout
AbsoluteLayout 可 以讓子元素指定準確的x/y坐標值,並顯示在屏幕上。(0,
0)為左上角,當向下或向右移動時,坐標值將變大。AbsoluteLayout沒有頁邊
框,允許元素之間互相重疊(盡管不推薦)。我們通常不推薦使用AbsoluteLayout,除非你有正當理由要使用它,因為它使界面代碼太過剛性,以至
於在不同的設備上可能不能很好地工作。
5.TableLayout
TableLayout 將子元素的位置分配到行或列中。android的
一個TableLayout由許多的TableRow組成,每個TableRow都會定義一個row(事實上,你可以定義其它的子對象,這在下面會解釋
到)。TableLayout容器不會顯示row、cloumns或cell的邊框線。每個row擁有0個或多個的cell;每個cell擁有一個
View對象。表格由列和行組成許多的單元格。表格允許單元格為空。單元格不能跨列,這與HTML中的不一樣。下圖顯示了一個TableLayout,圖
中的虛線代表不可視的單元格邊框。
列可以被隱藏,也可以被設置為伸展的從而填充可利用的屏幕空間,也可以被設置為強制列收縮直到表格匹配屏幕大小。對於更詳細信息,可以查看這個類的參考文檔。
TableLayout positions its children into rows and columns. TableLayout
containers do not display border lines for their rows, columns, or cells. The
table will have as many columns as the row with the most cells. A table can
leave cells empty, but cells cannot span columns, as they can in HTML.
TableRow objects are the child views of a TableLayout (each TableRow
defines a single row in the table). Each row has zero or more cells, each of
which is defined by any kind of other View. So, the cells of a row may be
composed of a variety of View objects, like ImageView or TextView objects. A
cell may also be a ViewGroup object (for example, you can nest another
TableLayout as a cell).
TableLayout和HTML的基本上類似,還提供TableRow class, 直接等價與比如說要做成一個類似下面的HTML葉面
I am textview1I am textview2
[OK button]
[Cancel button]android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
android:text="I am textview 1" />
android:paddingLeft = "20px"
android:width = "200px"
android:text="I am textview 2"
/>
android:id="@+id/Button02" android:text="Ok"
>
>
10. android 怎樣讓兩個button控制項挨在一起,左右對齊 沒有距離
Android中兩個Button可以使用線性布局LinearLayout來包含。
控制項之間的間距有兩種設置:
android:layout_margin="10dp" 外邊距
android:padding="10dp" 內邊距
在Button中將android:layout_margin="0dp" android:padding="0dp"
即將內外兩個間距都設置為0即可