Android tablelayout隐藏顶部按钮
在我的应用程序中,我有一个带有26个按钮的表格布局。我已经做了一排,每个按钮有两个。 我的代码如下:Android tablelayout隐藏顶部按钮,android,android-layout,Android,Android Layout,在我的应用程序中,我有一个带有26个按钮的表格布局。我已经做了一排,每个按钮有两个。 我的代码如下: <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="fill_parent" android:layout_width="fill_parent" android:scro
<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>
当我在模拟器中运行它时,它看起来是这样的:
最上面的四个按钮完全隐藏。有人知道为什么会这样吗。请帮忙。提前感谢。要解决您的问题,您需要更改: 近:
发件人:
android:layout\u gravity=“center”
到
android:layout\u gravity=“top”
这将使您的
表格视图
由“ScrollView”从顶部定位,而不是从中心定位。我已经运行了您的代码,问题是ScrollView。
如果您想在屏幕上显示所有内容,可以查看此否,这是触摸屏幕顶部滚动条时的图像。我不希望布局适合屏幕。代码隐藏了视图的顶部部分(前4个按钮),即使滚动条位于顶部。我将您的布局复制粘贴到模拟器上,坦率地说,问题仍然存在,正如您所解释的:)请原谅我的无知。解决方案在更新的答案中。我不明白。请帮忙。
<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="**">