2012-07-12 83 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" />