java 我的列表视图没有填充父级
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7175770/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
my listview doesn't fill parent
提问by Tsunaze
<RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" <TextView android:id="@+id/tv_test" android:text="Test " android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ListView android:id="@+id/list_test" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_below="@id/tv_test" ></ListView> </RelativeLayout>
<RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" <TextView android:id="@+id/tv_test" android:text="Test " android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ListView android:id="@+id/list_test" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_below="@id/tv_test" ></ListView> </RelativeLayout>
And everything is in a ScrollView, i don't know why but the relative layout seems to set a wrap content. And it makes the ListView small and not taking the whole place.
一切都在 ScrollView 中,我不知道为什么,但相对布局似乎设置了换行内容。它使 ListView 变小而不是占据整个地方。
I don't know if it's useful but here's my java code :
我不知道它是否有用,但这是我的 Java 代码:
public class ShowView extends Activity{
ListView lv;
ArrayAdapter<String> adapter;
String[] myList = {"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Height", "Nine", "Ten"};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.show);
lv = (ListView) findViewById(R.id.list_test);
adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, myList);
adapter.setDropDownViewResource(android.R.layout.simple_list_item_1);
lv.setAdapter(adapter);
}
}
回答by droid kid
I think you ScrollView is not filling the entire screen. Use this inside scrollView
我认为您 ScrollView 没有填满整个屏幕。在滚动视图中使用它
android:fillViewport="true"
回答by Mark Allison
Replace the RelativeLayout
with a vertical LinearLayout
, and set android:layout_weight="1"
and android:layout_height="wrap_content"
on your ListView:
将 替换RelativeLayout
为垂直LinearLayout
,android:layout_weight="1"
并android:layout_height="wrap_content"
在您的 ListView 上设置和:
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/tv_test"
android:text="Test "
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ListView
android:id="@+id/list_test"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_below="@id/tv_test" />
</LinearLayout>
Check out this articlefor further information on layout weights.
查看本文以获取有关布局权重的更多信息。
Also, I would remove the ScrollView
altogether. ListView
manages scrolling itself, and you will run in to all kinds of problems if you embed it inside a container which handles scrolling. If you want to scroll @is/tv_test
along with your ListView
content, then consider putting it inside your ListView
as a header. If you want it to remain static when the ListView
scrolls, then keep it outside the ListView
.
另外,我会ScrollView
完全删除。ListView
管理滚动本身,如果您将其嵌入处理滚动的容器中,您将遇到各种问题。如果你想@is/tv_test
随着你的ListView
内容滚动,那么考虑把它放在你ListView
的标题中。如果您希望它在ListView
滚动时保持静态,请将其放在ListView
.