2011-04-29 66 views
0

enter image description here朋友,Android的布局体重问题

我写了下面的布局代码和按钮,但它似乎没有工作的任何一个指导我我在做什么错误?

![<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
> 

    <LinearLayout 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:background="@color/color_panel_background" 
    > 

     <ImageButton 
     android:layout_height="wrap_content" 
     android:id="@+id/currentLocation" 
     android:layout_weight="1" 
     android:layout_width="fill_parent" 
     android:src="@drawable/current_location_icon" 
     /> 

     <ImageButton 
     android:layout_height="wrap_content" 
     android:id="@+id/searchCity" 
     android:layout_weight="1" 
     android:layout_width="fill_parent" 
     android:src="@drawable/search_icon" 
     /> 

     <ImageButton 
     android:layout_height="wrap_content" 
     android:id="@+id/home" 
     android:layout_weight="1" 
     android:layout_width="fill_parent" 
     android:src="@drawable/home_icon" 
     /> 

    </LinearLayout> 

</RelativeLayout>][2] 

回答

0

中间按钮的绘图明显大于其他两个。你用wrap_content设置按钮的高度,所以中间按钮变大。重量与此无关。它只是定义了使用fill_parent时项目需要多少空间。 解决这个问题的最简单方法是将layout_height更改为固定值(使用dp作为单位) 或更改绘图的大小,使图像始终以相同的大小开始。

竖起大拇指为你提问的方式。屏幕截图和相关代码。祝大家会这么做:)

0

变化android:layout_height"wrap_content",如果你希望他们有相同的高度一些常数。

0

变化的线性布局高度线性布局内的一些常数和 更改对象layout_height到FILL_PARENT

0
在水平

:如果你的孩子视图,然后用= 0dp 设定重量设定垂直方向:如果您为子视图设置重量,则设置height = 0dp