Android横向模式切断顶部的按钮
我的申请有问题。我最近添加了ScrollView作为LinearLayout的父级。将设备方向翻转到横向时,顶部的按钮会被切断。当我向下滚动时,我可以看到最后一个按钮,它的末端有额外的“黑色空间”,只有顶部被切断。我环顾四周,不知道为什么会这样。这里有一些图片,你可以了解它的外观Android横向模式切断顶部的按钮,android,scrollview,android-linearlayout,Android,Scrollview,Android Linearlayout,我的申请有问题。我最近添加了ScrollView作为LinearLayout的父级。将设备方向翻转到横向时,顶部的按钮会被切断。当我向下滚动时,我可以看到最后一个按钮,它的末端有额外的“黑色空间”,只有顶部被切断。我环顾四周,不知道为什么会这样。这里有一些图片,你可以了解它的外观 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:gravity="center_vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center">
<Button
android:id="@+id/BeefButton"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="center"
android:background="@drawable/backgroundlayer"
android:drawableLeft="@drawable/beefbutton"
android:text="Beef"
android:textColor="#FFFFFF"
android:textSize="32px"
android:textColorHighlight="#FF6600"/>
<Button
android:id="@+id/PoultryButton"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_width="match_parent"
android:background="@drawable/backgroundlayer"
android:drawableLeft="@drawable/chickenbutton"
android:text="Poultry"
android:textColor="#FFFFFF"
android:textSize="32px"
android:textColorHighlight="#FF6600"/>
<Button
android:id="@+id/FishButton"
android:layout_height="wrap_content"
android:background="@drawable/backgroundlayer"
android:drawableLeft="@drawable/fishbutton"
android:text="Fish"
android:textColor="#FFFFFF"
android:textSize="32px"
android:textColorHighlight="#FF6600"
android:layout_gravity="center"
android:layout_width="match_parent"/>
<Button
android:id="@+id/PorkButton"
android:layout_height="wrap_content"
android:background="@drawable/backgroundlayer"
android:drawableLeft="@drawable/porkbutton"
android:text="Pork"
android:textColor="#FFFFFF"
android:textSize="32px"
android:textColorHighlight="#FF6600"
android:layout_gravity="center"
android:layout_width="match_parent"/>
<Button
android:id="@+id/VegetablesButton"
android:layout_height="wrap_content"
android:background="@drawable/backgroundlayer"
android:drawableLeft="@drawable/vegetablesbutton"
android:text="Vegetables"
android:textColor="#FFFFFF"
android:textSize="32px"
android:textColorHighlight="#FF6600"
android:layout_gravity="center"
android:layout_width="match_parent"/>
</LinearLayout>
</ScrollView>
删除线性布局上的
android:layout\u gravity=“center”
,当您将其更改为横向模式时,滚动视图的高度大于屏幕大小,因此它将使线性布局在滚动视图中居中,尽管删除它可能不是解决方案,但这正是导致此问题的原因
你可以考虑修改你的布局,使用ListVIEW能够成功地支持Field
< P>可能更为合理。我知道这是一个老线程,但是我花了两天时间来解决这个问题。虽然删除“布局重力”语句确实有助于解决截止问题,但无法居中的评论也是正确的。最终,在我看来,对我来说,这是一种黑客行为,它把scrollview放在一个以布局为中心的顶部,两个线性布局像孩子一样层叠在一起。此外,高度和宽度必须是scrollview和linearlayouts上的包裹内容。这不是最整洁的解决方案,但我尝试了所有方法都没有成功,包括在对象小于屏幕大小宽度时使用setlayoutparams在代码中设置重力。我希望这对某人有帮助 提示@slim said确实有效,但没有中心对齐(删除android:layout\u gravity=“center”
)
我的解决方案:
我用线性布局
将其重力设置为center
并让android:layout\u gravity=“center”
保留主布局来修复它:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">
<!-- .... the main long layout ... -->
</LinearLayout>
</ScrollView>
请发布您的布局。对于纵向和横向模式,您有相同的设置吗?另外,您不使用ListView而不是带有ScrollView的LinearLayout,有什么原因吗?您的列表项目是否总是完全相同,并且只有5个?是的,它们的方式完全相同,只有5个项目。除此之外,没有办法让我的项目像那样列在中间,对吗-(您可以在ScrollView上添加“layout\u gravity=“center”,并将其包装内容。这样,当有足够的空间时,视图将位于其容器的中心,而当没有足够的空间时,视图将正确滚动。)。