滚动视图上方的线性布局
我有一个简单的 android 布局,由包含表格布局的滚动视图组成。该表显示正确,但我想在滚动视图上方添加一个静态标题,以便基本上表中列的标签始终保留在屏幕顶部。但是,当我在布局文件中的
上方添加
时,它会使其全部消失。
谁能发现我的 xml 文件做错了什么?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="top" >
<LinearLayout
android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableLayout
android:id="@+id/mainTable"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</ScrollView>
</LinearLayout>
事实上,我看不到滚动视图或表格布局,但如果我删除 header
线性布局,它会显示得很好。
I've got a simple android layout consisting of a scrollview containing a tablelayout. This table displays properly, but I would like to add a static header above the scrollview, so that basically the labels for the columns in the table remain at the top of the screen always. However, when I add a <LinearLayout>
above the <ScrollView>
in my layout file, it makes it all disappear.
Can anyone spot what I've done wrong with my xml file?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="top" >
<LinearLayout
android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableLayout
android:id="@+id/mainTable"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</ScrollView>
</LinearLayout>
As it is, I do not see the scrollview or table layout, but if I remove the header
linearlayout, it displays just fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的滚动视图的layout_height设置为fill_parent。使用wrap_content。
Your scrollview's layout_height is set to fill_parent. Use wrap_content.
LinearLayouts 需要具有
android:orientation参数设置。
LinearLayouts need to have the
android:orientation
parameter set.您必须将父 LinearLayout 的方向设置为垂直!默认情况下设置为水平,这样您就看不到 ScrollView。
你可以试试这个:
希望这有帮助!
You have to set the orientation of the parent LinearLayout to vertical! By default is set to horizontal that's way you don't see the ScrollView.
and you can try this:
Hope this helps!!