我有一个TableLayout,它动态地填充了许多行数据。它包含的数据多于屏幕所能容纳的数据,因此我要求它可以滚动。
我的问题是,当我将TableLayout放在ScrollView中时,它似乎会截断TableLayout顶部的许多行。
供参考,完整的代码在这里(问题是已经混乱已经适合所有)http://pastebin.com/w7Fi3Bzz
请参阅下文,了解与我遇到的问题相关的代码
这是没有ScrollView的XML:
<TableLayout
android:orientation="vertical"
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:id="@+id/tbl_statistics"
android:stretchColumns="*"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
>
</TableLayout>
它看起来像什么:
这是带有ScrollView的相同XML:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
>
<TableLayout
android:orientation="vertical"
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:id="@+id/tbl_statistics"
android:stretchColumns="*"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
>
</TableLayout>
</ScrollView>
这是表格的样子,你可以看到表格的顶部是截断的(它填充了相同的确切数据):
我在LinearLayout not expanding inside a ScrollView找到了类似的问题,但答案对我没有帮助。
答案 0 :(得分:2)
从 <body>
<div class="wrapper">
<div class="gradient">
<div class="logo">
<img src="logo-05.svg">
</div>
<div class="statement">
This is a blockquote. Someone said something really funny and it should be noted here. Aenean massa strong . Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In em enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam link dictum felis eu pede mollis pretium. This is a blockquote. Someone said something really funny and it should be noted here. Aenean massa strong . Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In em enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam link dictum felis eu pede mollis pretium.
</div>
</div>
</div>
.gradient {
height: calc(100%);
background: -webkit-linear-gradient(270deg, #FFCC33,#FF3366);
background: -moz-linear-gradient(270deg, #FFCC33,#FF3366);
background: -o-linear-gradient(270deg, #FFCC33,#FF3366);
background: -ms-linear-gradient(270deg, #FFCC33,#FF3366);
background: linear-gradient(180deg, #FFCC33,#FF3366);
position: fixed;
width: 100%;
background-color: #292c2f;
font-family: monospace;
overflow: hidden;
font-size: 100pt;
color: white;
z-index: -99;
}
.wrapper{
width: 100%;
height:100%;
position: relative;
}
.header{
width: 100%;
position: fixed;
}
.dates{
color:black;
z-index: 99;
display: inline-block;
float: left;
padding-top: 5px;
font-size: 20pt;
margin-left: -20px;
font-family: 'Roboto', sans-serif;
font-weight: 400;
letter-spacing: 1pt;
}
.year{
color:black;
margin-top: -10px;
z-index: 99;
display: inline-block;
top:25px;
font-size: 55pt;
margin-left: 20px;
font-family: 'Kavoon', sans-serif;
font-weight: 800;
letter-spacing:-3px;
}
.location{
right: 35px;
top: 35px;
text-align: right;
width: 100%;
position: fixed;
font-size: 20pt;
font-family: 'Roboto', sans-serif;
font-weight: 400;
color: black;
}
.logo{
margin-right: auto;
margin-left: auto;
width: 600px;
position: relative;
}
.statement{
position: relative;
font-size: 14pt;
color:black;
width:500px;
margin-right: auto;
margin-left: auto;
font-family: 'Roboto', sans-serif;
}
.footer ul {
text-align: center;
font-size: 14pt;
font-family: 'Roboto', sans-serif;
font-weight: 800;
width:100%;
display:inline-block;
text-transform: uppercase;
}
.footer-wrap{
color:black;
width: 100%;
text-align: center;
margin-bottom: 45px;
bottom: 0;
position: fixed;
padding:10;
display: inline-block;
}
元素中删除android:layout_gravity="center"
。
将TableLayout
添加到android:layout_weight="1"
元素。
清理并重建您的项目。
此外,ScrollView
属性仅适用于fillViewport
s。
答案 1 :(得分:2)
我只是通过将TableLayout插入到LinearLayout中解决了同样的问题,而LinearLayout只是ScrollView的子代。我尝试了所有其他变体但没有成功(fillViewport
为ScrollView
,android:layout_weight="1"
为TableLayout
。
我使用TableLayout
动态插入Views
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TableLayout
android:id="@+id/activity_displayFields_tableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp" />
</LinearLayout>
</ScrollView>