2012-06-11 34 views
1

我想创建一个适合按钮和ImageView之间的ListView。 我有一个RelativeLayout,它的顶部有一个按钮,底部有一个ImageView。 我想要一个ListView之间。这就是我所做的。我如何使一个按钮和ImageView垂直的ListView适合

我在按钮下看到我的listView,但它与底部的ImageView重叠。 那么我怎样才能让ListView上方的ImageView?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/control_panel" 
     android:layout_width="@dimen/mywidth" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <Button android:id="@+id/button" 
      android:layout_height="@dimen/button_size" 
      android:layout_width="@dimen/button_size" 
      android:scaleType="center" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:background="@drawable/btn_shutter" /> 

     <ListView android:id="@+id/image_list" 
      android:layout_width="@dimen/button_size" 
      android:layout_height="wrap_content" 
      android:drawSelectorOnTop="false" 
      android:layout_above="@+id/image" 
      android:layout_below="@+id/button"/> 

     <ImageView 
      android:id="@+id/image" 
      android:layout_width="@dimen/mywidth" 
      android:layout_height="@dimen/image_height" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentBottom="true"/> 

</RelativeLayout> 
+0

这是很难说没有知道你'@ dimen'变量的值。 – MrZander

+1

尝试计算按钮底部和ImageView顶部之间的距离,然后将其设置为运行时的ListView高度。 – Sam

回答

0

您是否设置了RelativeLayout?如果没有,您可以使用带权重的LinearLayout。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/control_panel" 
    android:layout_width="@dimen/mywidth" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <Button android:id="@+id/button" 
     android:layout_height="0px" 
     android:layout_width="@dimen/button_size" 
     android:scaleType="center" 
     android:layout_weight="1" 
     /> 

    <ListView android:id="@+id/image_list" 
     android:layout_width="@dimen/button_size" 
     android:layout_height="0px" 
     android:drawSelectorOnTop="false" 
     android:layout_weight="6"/> 

    <ImageView 
     android:id="@+id/image" 
     android:layout_width="@dimen/mywidth" 
     android:layout_height="0px" 
     android:layout_weight="1"/> 

+0

为什么在ListView中使用android:layout_weight =“6”?值6的含义是什么? layout_above,layout_below在LinearLayout中仍然有效吗? – michael

+0

糟糕,我的意思是删除layout_above和layout_below。我相应地修改了代码。 layout_weight =“6”基本上是父视图的哪个部分应由该元素填充的比率。按钮和图像的权重为1时,总数为8,因此列表视图占用LinearLayout的父元素的6/8。然后可以调整重量以适应您的需求。 – Nate

1

试试这个

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/control_panel" 
     android:layout_width="@dimen/mywidth" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <Button android:id="@+id/button" 
      android:layout_height="@dimen/button_size" 
      android:layout_width="wrap_content" 
      android:layout_alignParentTop="true" 
      android:background="@drawable/btn_shutter" /> 

     <ImageView 
      android:id="@+id/image" 
      android:layout_width="@dimen/mywidth" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true"/> 

     <ListView android:id="@+id/image_list" 
      android:layout_width="@dimen/button_size" 
      android:layout_height="fill_parent" 
      android:drawSelectorOnTop="false" 
      android:layout_above="@+id/image" 
      android:layout_below="@+id/button"/> 


</RelativeLayout>