2011-08-16 35 views
0

在我的应用程序中,我有一个26个按钮的桌面布局。我做了一排两个按钮。 我的代码如下:Android桌面布局隐藏顶部按钮

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_height="fill_parent" 
    android:layout_width="fill_parent" 
    android:scrollbars="vertical"> 
<TableLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_gravity="center" 
android:layout_height="fill_parent" 
android:layout_width="fill_parent" 
android:scrollbars="horizontal" 
android:paddingTop="4.5dp" 
android:stretchColumns="**"> 
<TableRow> 
<Button 
     android:id="@+id/sp1" 
     android:layout_height="40dp" 
     android:layout_width="100dp" 
     android:background="@drawable/selector3" 
     android:layout_marginBottom="7dp" 
     android:layout_marginRight="10dp" 
     android:text="Preventing Psoric Taint"/> 
<Button 
     android:text="Suffocation and Choking" 
     android:layout_height="40dp" 
     android:background="@drawable/selector3" 
     android:layout_width="100dp" 
     android:layout_marginBottom="7dp" 
     android:layout_marginRight="10dp" 
     android:id="@+id/sp2" /> 
</TableRow> 
<TableRow> 
<Button 
     android:text="Spots on the cranum due to collection of blood" 
     android:id="@+id/sp3" 
     android:layout_height="40dp" 
     android:background="@drawable/selector3" 
     android:layout_width="100dp" 
     android:layout_marginBottom="7dp" 
     android:layout_marginRight="10dp"/> 
<Button 
     android:id="@+id/sp4" 
     android:layout_height="40dp" 
     android:layout_width="100dp" 
     android:background="@drawable/selector3" 
     android:layout_marginBottom="7dp" 
     android:layout_marginRight="10dp" 
     android:text="Monstrocities and Deformities"/> 
</TableRow> 
<TableRow> 
<Button 
     android:id="@+id/sp5" 
     android:layout_marginBottom="7dp" 
     android:background="@drawable/selector3" 
     android:layout_marginRight="10dp" 
     android:layout_width="100dp" 
     android:layout_height="40dp" 
     android:text="Marks and Blemishes"/> 
<Button 
     android:id="@+id/sp6" 
     android:layout_width="100dp" 
     android:background="@drawable/selector3" 
     android:layout_height="40dp" 
     android:layout_marginBottom="7dp" 
     android:layout_marginRight="10dp" 
     android:text="Blue discoloration of the skin"/> 
    </TableRow> 
    <TableRow> 
<Button 
     android:id="@+id/sp7" 
     android:layout_width="100dp" 
     android:layout_height="40dp" 
     android:background="@drawable/selector3" 
     android:layout_marginBottom="7dp" 
     android:layout_marginRight="10dp" 
     android:text="Swelling of the head"/> 
<Button 
     android:id="@+id/sp8" 
     android:layout_width="100dp" 
     android:layout_height="40dp" 
     android:layout_marginBottom="7dp" 
     android:background="@drawable/selector3" 
     android:layout_marginRight="10dp" 
     android:text="Congenital Hernia"/> 
    </TableRow> 
    <TableRow> 
<Button 
     android:text="Induration of cellular tissue" 
     android:id="@+id/sp9" 
     android:layout_width="100dp" 
     android:background="@drawable/selector3" 
     android:layout_marginBottom="7dp" 
     android:layout_marginRight="10dp" 
     android:layout_height="40dp"/> 
<Button 
     android:text="Breast swelling" 
     android:id="@+id/sp10" 
     android:layout_width="100dp" 
     android:background="@drawable/selector3" 
     android:layout_marginBottom="7dp" 
     android:layout_marginRight="10dp" 
     android:layout_height="40dp"/> 
    </TableRow> 
    <TableRow> 
<Button 
     android:text="Coryza" 
     android:background="@drawable/selector3" 
     android:id="@+id/sp11" 
     android:layout_width="100dp" 
     android:layout_marginBottom="7dp" 
     android:layout_marginRight="10dp" 
     android:layout_height="40dp"/> 
<Button 
android:text="Opthalmia (Inflammation of eyes)" 
android:id="@+id/sp12" 
    android:layout_width="100dp" 
    android:background="@drawable/selector3" 
    android:layout_marginBottom="7dp" 
     android:layout_marginRight="10dp" 
    android:layout_height="40dp"/> 
</TableRow> 
<TableRow> 
<Button 
android:text="Excoriation" 
android:id="@+id/sp13" 
    android:layout_width="100dp" 
    android:background="@drawable/selector3" 
    android:layout_marginBottom="7dp" 
     android:layout_marginRight="10dp" 
    android:layout_height="40dp"/> 
<Button 
android:text="Aphthae" 
android:id="@+id/sp14" 
    android:layout_width="100dp" 
    android:layout_marginBottom="7dp" 
    android:background="@drawable/selector3" 
     android:layout_marginRight="10dp" 
    android:layout_height="40dp"/> 
</TableRow> 
<TableRow> 
<Button 
android:text="Spasms on the chest" 
android:id="@+id/sp15" 
    android:layout_width="100dp" 
    android:layout_marginBottom="7dp" 
    android:background="@drawable/selector3" 
     android:layout_marginRight="10dp" 
    android:layout_height="40dp"/> 
    <Button 
android:text="Convulsions" 
android:id="@+id/sp16" 
    android:layout_width="100dp" 
    android:layout_marginBottom="7dp" 
     android:layout_marginRight="10dp" 
     android:background="@drawable/selector3" 
    android:layout_height="40dp"/>  
</TableRow> 
<TableRow> 
    <Button 
android:text="Milk Crust" 
android:id="@+id/sp17" 
    android:layout_width="100dp" 
    android:layout_marginBottom="7dp" 
    android:background="@drawable/selector3" 
     android:layout_marginRight="10dp" 
    android:layout_height="40dp"/> 
    <Button 
android:text="Red gum" 
android:id="@+id/sp18" 
    android:layout_width="100dp" 
    android:layout_marginBottom="7dp" 
     android:layout_marginRight="10dp" 
     android:background="@drawable/selector3" 
    android:layout_height="40dp"/> 
</TableRow> 
<TableRow> 
    <Button 
android:text="Scald Head" 
android:id="@+id/sp19" 
    android:layout_width="100dp" 
    android:background="@drawable/selector3" 
    android:layout_marginBottom="7dp" 
     android:layout_marginRight="10dp" 
    android:layout_height="40dp"/> 
    <Button 
android:text="Heat Spots" 
android:id="@+id/sp20" 
    android:layout_width="100dp" 
    android:layout_marginBottom="7dp" 
    android:background="@drawable/selector3" 
     android:layout_marginRight="10dp" 
    android:layout_height="40dp"/>  
</TableRow> 
<TableRow> 
    <Button 
android:text="Tetanus" 
android:id="@+id/sp21" 
    android:background="@drawable/selector3" 
    android:layout_width="100dp" 
    android:layout_marginBottom="7dp" 
     android:layout_marginRight="10dp" 
    android:layout_height="40dp"/> 
    <Button 
android:text="Weaning complaints" 
android:id="@+id/sp22" 
    android:background="@drawable/selector3" 
    android:layout_width="100dp" 
    android:layout_marginBottom="7dp" 
     android:layout_marginRight="10dp" 
    android:layout_height="40dp"/> 
    </TableRow> 
    <TableRow> 

    <Button 
android:text="Erysipelas" 
android:id="@+id/sp23" 
    android:layout_width="100dp" 
    android:background="@drawable/selector3" 
    android:layout_marginBottom="7dp" 
     android:layout_marginRight="10dp" 
    android:layout_height="40dp"/> 
    <Button 
android:text="Dentition" 
android:id="@+id/sp24" 
android:layout_marginBottom="7dp" 
    android:background="@drawable/selector3" 
     android:layout_marginRight="10dp" 
    android:layout_width="100dp" 
    android:layout_height="40dp"/> 
    </TableRow> 
    <TableRow> 

    <Button 
android:text="Bed Wetting" 
android:id="@+id/sp25" 
android:layout_marginBottom="7dp" 
    android:background="@drawable/selector3" 
     android:layout_marginRight="10dp" 
    android:layout_width="100dp" 
    android:layout_height="40dp"/> 

    <Button 
android:text="Worms" 
android:layout_marginBottom="7dp" 
     android:layout_marginRight="10dp" 
     android:background="@drawable/selector3" 
android:id="@+id/sp26" 
    android:layout_width="100dp" 
    android:layout_height="40dp"/> 

    </TableRow>      
</TableLayout> 
</ScrollView> 

而且它看起来像这样,当我在模拟器中运行它: enter image description here

顶部四个按键得到完全隐藏。有谁知道为什么会发生这种情况。请帮忙。提前致谢。

回答

1

要解决你的问题,你需要改变:

附近:

<TableLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_gravity="center" 
android:layout_height="fill_parent" 
android:layout_width="fill_parent" 
android:scrollbars="horizontal" 
android:paddingTop="4.5dp" 
android:stretchColumns="**"> 

来自:

android:layout_gravity="center"

android:layout_gravity="top"

这将使您的TableView由顶部的“ScrollView”锚定,而不是从中心锚定。

+0

一看不行,这是当滚动条在屏幕的顶部触及图像。我不希望布局适合屏幕。即使滚动条位于顶部,代码也会隐藏视图的顶部(顶部4个按钮)。 –

+0

我复制粘贴你的布局到模拟器,坦率地说,问题仍然存在,正如你解释:)请原谅我的无知。解决方案是更新的答案。 – pkk

+0

是的,它工作。非常感谢你。 –

0

我跑过你的代码,问题是滚动视图。 如果您想不完的事你屏幕上,你可以采取这种excellent post.

+0

我不明白。请帮忙。 –