Android 设置包含listView的相对布局的高度
我目前正在开发一个Android应用程序,我有一个关于布局的问题。在我的XML布局文件中,我创建了一个相对布局(填充父视图表示宽度,包裹内容表示高度),其中包含一个列表视图(或者可能是一个可消耗的列表视图-填充父视图表示高度和宽度)。在相应的activityoncreate方法中,我只是设置了与我的列表对应的适配器,并将其附加到我的列表中。问题是,当我运行我的应用程序时,相对布局的大小只有93dip,因此当我希望相对布局高度保持在列表当前大小时,它会隐藏我的列表,该列表的大小从67到210dip(创建或恢复活动时,活动中的操作永远不会改变大小)。有人能想出解决办法吗 一些代码被问及:Android 设置包含listView的相对布局的高度,android,listview,layout,android-relativelayout,Android,Listview,Layout,Android Relativelayout,我目前正在开发一个Android应用程序,我有一个关于布局的问题。在我的XML布局文件中,我创建了一个相对布局(填充父视图表示宽度,包裹内容表示高度),其中包含一个列表视图(或者可能是一个可消耗的列表视图-填充父视图表示高度和宽度)。在相应的activityoncreate方法中,我只是设置了与我的列表对应的适配器,并将其附加到我的列表中。问题是,当我运行我的应用程序时,相对布局的大小只有93dip,因此当我希望相对布局高度保持在列表当前大小时,它会隐藏我的列表,该列表的大小从67到210dip
<LinearLayout android:id="@+id/content"
android:layout_width="fill_parent"
android:background="@drawable/row"
android:layout_below="@+id/header"
android:layout_height="wrap_content">
<ListView android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/listrow"/>
</LinearLayout>
非常感谢您的帮助
Benja我有一个类似的情况。当我将父布局更改为LinearLayout时,它正在工作。下面是代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/LinearLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageButton
android:id="@+id/prev"
android:layout_width="106dip"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="@null"
android:onClick="prev"
android:paddingTop="8dip"
android:src="@drawable/previous" >
</ImageButton>
<ImageButton
android:id="@+id/next"
android:layout_width="106dip"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="@null"
android:onClick="next"
android:paddingTop="8dip"
android:src="@drawable/next" >
</ImageButton>
<ImageButton
android:id="@+id/Logout"
android:layout_width="106dip"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="@null"
android:onClick="logout"
android:paddingTop="8dip"
android:src="@drawable/logout1"
android:text="@string/Logout" >
</ImageButton>
</LinearLayout>
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="330dip" >
</ListView>
<TextView
android:id="@android:id/empty"
android:layout_width="fill_parent"
android:layout_height="338dip"
android:text="@string/EmptyList"
android:textSize="35dip" />
<LinearLayout
android:id="@+id/LinearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageButton
android:id="@+id/prev1"
android:layout_width="106dip"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="@null"
android:onClick="prev"
android:src="@drawable/previous" >
</ImageButton>
<ImageButton
android:id="@+id/next1"
android:layout_width="106dip"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="@null"
android:onClick="next"
android:src="@drawable/next" >
</ImageButton>
<ImageButton
android:id="@+id/Logout"
android:layout_width="106dip"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="@null"
android:onClick="logout"
android:src="@drawable/logout1"
android:text="@string/Logout" >
</ImageButton>
</LinearLayout>
</LinearLayout>
您可以添加布局和一些代码吗?为什么不使用LinearLayout?在你的项目中使用RelativeLayout有什么具体的原因吗?理论上我可以修改它,但我不想修改,因为这对我来说意味着很多变化,但对其他参与项目的人来说也是如此。。。如果我真的必须这样做,我会的,但我首先想知道我的问题是否存在一个相对布局的解决方案…对不起,我在测试你的解决方案,同时给我的问题添加了一些代码。。。但不是。。。这在我的情况下不起作用。。。完全相同的问题…除了列表视图,还有其他视图吗?如果listview是唯一的子视图,请尝试删除父布局…如果没有解决问题,为什么会接受此答案?你还需要答案吗?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/LinearLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageButton
android:id="@+id/prev"
android:layout_width="106dip"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="@null"
android:onClick="prev"
android:paddingTop="8dip"
android:src="@drawable/previous" >
</ImageButton>
<ImageButton
android:id="@+id/next"
android:layout_width="106dip"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="@null"
android:onClick="next"
android:paddingTop="8dip"
android:src="@drawable/next" >
</ImageButton>
<ImageButton
android:id="@+id/Logout"
android:layout_width="106dip"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="@null"
android:onClick="logout"
android:paddingTop="8dip"
android:src="@drawable/logout1"
android:text="@string/Logout" >
</ImageButton>
</LinearLayout>
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="330dip" >
</ListView>
<TextView
android:id="@android:id/empty"
android:layout_width="fill_parent"
android:layout_height="338dip"
android:text="@string/EmptyList"
android:textSize="35dip" />
<LinearLayout
android:id="@+id/LinearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageButton
android:id="@+id/prev1"
android:layout_width="106dip"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="@null"
android:onClick="prev"
android:src="@drawable/previous" >
</ImageButton>
<ImageButton
android:id="@+id/next1"
android:layout_width="106dip"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="@null"
android:onClick="next"
android:src="@drawable/next" >
</ImageButton>
<ImageButton
android:id="@+id/Logout"
android:layout_width="106dip"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="@null"
android:onClick="logout"
android:src="@drawable/logout1"
android:text="@string/Logout" >
</ImageButton>
</LinearLayout>
</LinearLayout>