2012-07-12 99 views

回答

1

您是否需要中間視圖或其中三個?

對於前者,只需在左側和右側創建一個60dp填充的視圖。

對於後者,創建60dp寬度的固定邊緣視圖,對於中間的視圖,設置以下屬性:layout_width的0dp和layout_weight的1。

將所有這些視圖放入LinearLayout中。

+0

非常感謝,左側和右側的填充解決了我的問題:)我可以使用layout_weight =「1」或layout_width =「fill_parent」,兩者都可以正常工作 – krinn 2012-07-12 20:49:03

1
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="60dp" 
    android:orientation="horizontal" > 

    <FrameLayout 
    android:layout_width="60dp" 
    android:layout_height="fill_parent" 
    android:background="#333333" 
    /> 

    <FrameLayout 
    android:layout_width="0dp" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    android:background="#FF3333" 
    /> 

    <FrameLayout 
    android:layout_width="60dp" 
    android:layout_height="fill_parent" 
    android:background="#333333" 
    /> 

</LinearLayout> 
+0

當你爲佈局添加一個wight時,你應該把0dp作爲伸展的度量。看到我的答案。 – Santacrab 2012-07-12 15:32:27

+0

是的,我只是編輯它。謝謝 – fiddler 2012-07-12 15:34:25

0

的線性佈局與3個元素內:

左右elemend會有機器人:layout_width = 「60dp」,而中央的一個將具有:

android:layout_width="0dp" 
android:layout_weight="1" 

這樣它就會適應設備屏幕寬度

0

只需在任何元素中使用layout_margin屬性,例如TextVi ew:

<TextView 
    android:id="@+id/text" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="60dp" 
    android:layout_marginRight="60dp" 
    android:background="#ff0000" />