android layout 按比例布局

2021-08-31 22:41:57 字數 1174 閱讀 8554

為了建立比例大小的子view,可以將linearlayout的寬度和高度設為fill_parent, 而將子view的寬度或是高度設為0,然後為子view設定不同權重(weight) ,這樣子view的大小就會權值成比例。

本例使用橫向linearlayout,linearlayout的android:layout_width=」match_parent」,表示將使用整個螢幕寬度。

對於linearlayout的幾個子view,將它們的寬度都定義為0,android:layout_width=」0dip」,然後使用layout_weight 為每個view指定寬度比例,本例為每個textview都使用了相同的權值,因此四個textview將會有相同的寬度。這樣對於那些顯示文字比較長的textview的高度就變為多行。

android:orientation=」horizontal」

android:layout_width=」match_parent」

android:layout_height=」wrap_content」>

android:layout_width=」0dip」

android:layout_height=」match_parent」

android:layout_weight=」1″

android:text=」@string/linear_layout_7_small」/>

android:layout_width=」0dip」

android:layout_height=」match_parent」

android:layout_weight=」1″

android:text=」@string/linear_layout_7_big」/>

android:layout_width=」0dip」

android:layout_height=」match_parent」

android:layout_weight=」1″

android:text=」@string/linear_layout_7_small」 />

android:layout_width=」0dip」

android:layout_height=」wrap_content」

android:layout_weight=」1″

android:text=」@string/linear_layout_7_wrap」/>

Android layout無法載入

布局無法載入,xml也沒有錯誤,提示note one or more layouts are missing the layout width or layout height attributes.these are required in most layouts 關閉android studi...

Android Layout基本概念

1.framelayout 單幀布局 其子元素沒有位置概念,所有元素放在左上角,但執行速度快 2.linearlayout 線性布局 線性布局,其子元素按水平或垂直方向挨著排 3.relativelayout 相對布局 相對布局,子元素可以相對relativelayout或其它子元素進行布局,其子元...

Android layout的橫豎屏處理

橫豎屏處理是開發應用是比較基礎的乙個要點,幾乎都會用到。一 layout land和layout prot的區別與使用 預設情況下,建立的android專案裡只有乙個layout資料夾,儘管這樣也可以橫豎屏切換用,但是某些布局橫屏過後閒的格外的醜。橫屏過後就顯示的不全了,有時候看著比較糾結。所以需要...