【发布时间】:2012-01-11 08:29:23
【问题描述】:
我目前正在开发一个 Android 应用,但我遇到了有关布局的问题。在我的 XML 布局文件中,我创建了一个相对布局(宽度为 fill_parent,高度为 wrap_content),其中包含一个列表视图(或者可能是一个消耗性列表视图 - 高度和宽度的 fill_parent)。在对应的activity onCreate方法中,我只是设置了我的list对应的adapter,并附加到我的list中。问题是,当我运行我的应用程序时,相对布局只有 93dip 的大小,因此当我希望相对布局高度坚持列表当前大小(大小永远不会在创建或恢复活动时通过活动中的操作而改变)。有没有人知道解决这个问题的方法?
一些代码要求:
<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);
非常感谢您的帮助!
本杰
【问题讨论】:
-
你能添加布局和一些代码吗?
-
为什么不用LinearLayout?在你的项目中使用RelativeLayout有什么特别的原因吗?
-
好吧,理论上我可以修改它,但我不希望这样做,因为这意味着对我和其他从事该项目的人来说会有很多变化......如果我真的必须我会,但我首先想知道我的相对布局问题是否存在解决方案......
标签: android listview layout android-relativelayout