Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在relativelayout下调整Android布局列表视图高度_Android_Layout - Fatal编程技术网

在relativelayout下调整Android布局列表视图高度

在relativelayout下调整Android布局列表视图高度,android,layout,Android,Layout,我想添加一个listview或tableview占据屏幕的2/3,然后在listview的正下方的中央会有一个巨大的按钮。现在的问题是listview占据了整个屏幕的高度。我无法调整图形布局上的高度。我只想买5件高度尺寸的东西。下面是屏幕上的按钮中心 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:orientation="vertical" android:layout_width="

我想添加一个listview或tableview占据屏幕的2/3,然后在listview的正下方的中央会有一个巨大的按钮。现在的问题是listview占据了整个屏幕的高度。我无法调整图形布局上的高度。我只想买5件高度尺寸的东西。下面是屏幕上的按钮中心

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:id="@+id/relativeLayout"
   android:padding="3dp" xmlns:android="http://schemas.android.com/apk/res/android">
 <ListView android:layout_height="wrap_content"
  android:id="@+id/listView1"
   android:layout_width="fill_parent" android:layout_alignParentLeft="true" 
   android:layout_alignParentTop="true"></ListView>

</RelativeLayout>

根据您在问题中所说的,垂直线性布局听起来更适合您。 这样,通过将两个视图放置在顶级线性布局中,可以让ListView占据屏幕的三分之二,并使用权重在屏幕上分布视图

例如:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
    <ListView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="2" >
    </ListView>
    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" >
        <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"/>
    </RelativeLayout>
</LinearLayout>



这对我很有效。谢谢但是,除了上面的android:layout\u,我还必须使用下面的属性android:layout\u,以确保listview位于我的应用程序中的其他两个视图之间。android:layout\u alignParentBottom属性可能会导致按钮下方隐藏一些列表项。
    <?xml version="1.0" encoding="utf-8"?>

    <RelativeLayout
       android:orientation="vertical"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       android:id="@+id/relativeLayout"
       android:padding="3dp" xmlns:android="http://schemas.android.com/apk/res/android">

<ListView android:layout_height="fill_parent"
      android:id="@+id/listView1"
      android:layout_above="@+id/button1"
      android:layout_width="fill_parent"></ListView>

<Button android:layout_height="wrap_content"
      android:id="@+id/button1"
      android:layout_alignParentBottom="true"
      android:layout_width="fill_parent"></Button >

    </RelativeLayout>