动态视图高

问题描述:

我是新的Android平台。我试图制作一个视图,将屏幕分为三部分。第一部分应该是200dip高,第三部分应该是50高,中间部分应该留在中间的剩余部分。有什么办法可以实现它吗?我尝试了一些方法,但是它不起作用或应用程序崩溃。 感谢您的帮助 Patrik动态视图高

当然。使用一个看起来像这样的RelativeLayout。

<?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"> 
    <!-- Defining the top view --> 
    <View android:layout_alignParentTop="true" 
    android:layout_height="200dip" 
    android:layout_width="fill_parent" 
    android:id="@+id/top_view" 
    android:background="#FFFF00"/> 
    <!-- Defining the bottom view --> 
    <View android:layout_alignParentBottom="true" 
    android:layout_height="50dip" 
    android:layout_width="fill_parent" 
    android:id="@+id/bottom_view" 
    android:background="#00FFFF"/> 
    <!-- Defining the view in between those views --> 
    <View android:layout_above="@id/bottom_view" 
    android:layout_below="@id/top_view" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#FF0000"/> 
</RelativeLayout> 

在代码中为您提供了注释。

+0

我喜欢这个建议甚至比我的更好。 +1 – Ralkie 2010-10-27 09:44:01

我通常通过设置固定视图为特定值(例如android:layout_height="200dp")layout_height /宽度,并用为android:layout_height="wrap_content"动态查看设置android:layout_weight="1"实现这一点。在这种情况下,LinearLayout应该被用作包含ViewGroup。