设置包含 listView 的相对布局的高度
我目前正在开发一个 Android 应用程序,并且遇到了有关布局的问题。在我的 XML 布局文件中,我创建一个相对布局(fill_parent 表示宽度,wrap_content 表示高度),其中包含一个列表视图(或者可能是一个可消耗的列表视图 - fill_parent 表示高度和宽度)。在相应的活动onCreate方法中,我只是设置了与我的列表对应的适配器并将其附加到我的列表中。问题是,当我运行我的应用程序时,相对布局的大小只有 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>
在java文件中(其中snapRecords是我的对象列表):
m_panel = (RelativeLayout)findViewById(R.id.lastFareRecordPanel);
ListView lv = (ListView)m_panel.findViewById(R.id.list);
final QuickSnapBookmarksAdapter adapter = new QuickSnapBookmarksAdapter(snapRecords, getApplicationContext(), this, lv);
lv.setAdapter(adapter);
非常感谢您的帮助!
本贾
I'm currently developing an Android app and I've got an issue concerning layout. In my XML layout file, I create a relative layout (fill_parent for width and wrap_content for height) which contains a list View (or possibly an expendable List View - fill_parent for height and width). In the corresponding activity onCreate method, I just set the adapter corresponding to my list and attach it to my list. The problem is that when I run my app the relative layout only has a size of 93dip and so it hides my list which has a size from 67 to 210dip when I would like the relative layout height to stick to the list current size (The size will never change through action in the activity just possibly when creating or resuming the activity). Would anyone have an idea of a solution to fix that ?
Some code as asked :
<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>
And in the java file (where snapRecords is my object lists):
m_panel = (RelativeLayout)findViewById(R.id.lastFareRecordPanel);
ListView lv = (ListView)m_panel.findViewById(R.id.list);
final QuickSnapBookmarksAdapter adapter = new QuickSnapBookmarksAdapter(snapRecords, getApplicationContext(), this, lv);
lv.setAdapter(adapter);
Many thanks in advance for your help !
Benja
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了类似的情况。当我将父布局更改为 LinearLayout 时,它正在工作。代码如下:
I had a similiar situation.When I changed parent layout into LinearLayout, it is working.Here is the code: