2011-12-19 69 views
0

我的应用程序的布局设置为480dpi宽,480/4是120.所以,如果我在应用程序顶部有4个按钮,并且我将其设置为120dpi宽,为什么按钮占用一半屏幕?!我怎样才能让按钮在顶部平均分配尺寸?活动元素的宽度不正确?

在这里,我只是增加了4个按键在顶部:

那么前两个按钮是120 dpi的宽:

+0

发表您的布局xml文件代码.. – user370305 2011-12-19 05:28:58

回答

2

检查了这一点:

<LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
     <Button 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"> 
     </Button> 
     <Button 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"> 
     </Button> 
     <Button 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"> 
     </Button> 
     <Button 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"> 
     </Button> 
    </LinearLayout> 
+0

嗯。那没有做任何事情。我仍然看不到按钮 – Cole 2011-12-19 05:42:38

+0

发布您的代码。 – josephus 2011-12-19 05:44:34

+0

好吧,它的工作。我必须在我的其他LinearLayout中添加该LinearLayout。谢谢您的帮助! – Cole 2011-12-19 05:51:30

1

可以使用FILL_PARENT参数进行布局宽度并为每个按钮添加一个权重1以获得期望的效果

+0

谢谢回答得这么快。所以每个按钮的宽度是“FILL_PARENT”,Activity的LinearLayout仍然是“match_parent”?你是什​​么意思“添加一个重量1”的按钮?当我这样做,它说我需要提供一个layout_width属性,我看不到按钮。 – Cole 2011-12-19 05:36:08

0

试试这个

<TableRow android:layout_width="fill_parent" 
    android:weightSum="100" android:layout_height="wrap_content"> 
    <Button android:text="Button" android:layout_weight="25" 
     android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
    <Button android:text="Button" android:layout_width="wrap_content" 
     android:layout_weight="25" android:layout_height="wrap_content"></Button> 
    <Button android:text="Button" android:layout_weight="25" 
     android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
    <Button android:text="Button" android:layout_weight="25" 
     android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
</TableRow> 
相关问题