Android 布局不会横向垂直滚动
您好 Stack Overflow 社区,
我希望您能帮助解决我遇到的 Android 布局问题。当我的活动处于横向时,我似乎无法使其垂直滚动。
我有一个滚动视图父级和一个相对布局子级。在相对布局中,我有各种元素。纵向方向看起来很棒,但在横向方向上,我的图像视图会缩小以适应屏幕中的所有内容,而不是具有我想要的垂直滚动。
任何帮助总是非常感谢并继续编码!
-AmarettoSlim
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView"
android:layout_height="fill_parent" android:layout_width="fill_parent" android:fillViewport="true" android:scrollbars="vertical">
<RelativeLayout android:id="@+id/MainScreen" android:background="@color/appbackground" android:layout_width="fill_parent" android:layout_height="fill_parent" android:isScrollContainer="true" android:scrollbars="vertical" android:scrollbarStyle="insideOverlay">
<Spinner android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignLeft="@+id/cspinner" android:layout_marginTop="48dp" android:id="@+id/pspinner" android:layout_above="@+id/buttonGo"></Spinner>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@+id/cspinner" android:layout_toLeftOf="@+id/cspinner" android:layout_marginRight="14dp" android:layout_marginTop="14dp" android:id="@+id/labelC" android:text="@string/lblC"></TextView>
<ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/logo" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="14dp" android:id="@+id/bannerLogo"></ImageView>
<TextView android:id="@+id/labelPrice" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/lblP" android:layout_alignTop="@+id/pspinner" android:layout_alignRight="@+id/labelC" android:layout_marginTop="16dp"></TextView>
<Spinner android:layout_height="wrap_content" android:id="@+id/cspinner" android:layout_width="wrap_content" android:layout_above="@+id/labelP" android:layout_centerHorizontal="true"></Spinner>
<ImageView android:layout_height="wrap_content" android:id="@+id/imgHat" android:layout_width="wrap_content" android:src="@drawable/bowlericon" android:layout_centerHorizontal="true" android:layout_below="@+id/bannerLogo" android:layout_above="@+id/cspinner"></ImageView>
<Button android:id="@+id/buttonGo" android:layout_width="fill_parent" android:text="@string/btnRun" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true"></Button>
</RelativeLayout>
</ScrollView>
Hi Stack Overflow Community,
I'm hoping you can help with an Android layout issue I'm having. I can't seem to get my activity to scroll vertically when I have it in landscape orientation.
I have a scrollview parent and a relativelayout child. Inside the relativelayout I have my various elements. Portrait orientation looks great but in landscape the imageview I have shrinks to fit everything in the screen verus having a vertical scroll which I want.
Any help is always greatly appreciated and code on!
-AmarettoSlim
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView"
android:layout_height="fill_parent" android:layout_width="fill_parent" android:fillViewport="true" android:scrollbars="vertical">
<RelativeLayout android:id="@+id/MainScreen" android:background="@color/appbackground" android:layout_width="fill_parent" android:layout_height="fill_parent" android:isScrollContainer="true" android:scrollbars="vertical" android:scrollbarStyle="insideOverlay">
<Spinner android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignLeft="@+id/cspinner" android:layout_marginTop="48dp" android:id="@+id/pspinner" android:layout_above="@+id/buttonGo"></Spinner>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@+id/cspinner" android:layout_toLeftOf="@+id/cspinner" android:layout_marginRight="14dp" android:layout_marginTop="14dp" android:id="@+id/labelC" android:text="@string/lblC"></TextView>
<ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/logo" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="14dp" android:id="@+id/bannerLogo"></ImageView>
<TextView android:id="@+id/labelPrice" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/lblP" android:layout_alignTop="@+id/pspinner" android:layout_alignRight="@+id/labelC" android:layout_marginTop="16dp"></TextView>
<Spinner android:layout_height="wrap_content" android:id="@+id/cspinner" android:layout_width="wrap_content" android:layout_above="@+id/labelP" android:layout_centerHorizontal="true"></Spinner>
<ImageView android:layout_height="wrap_content" android:id="@+id/imgHat" android:layout_width="wrap_content" android:src="@drawable/bowlericon" android:layout_centerHorizontal="true" android:layout_below="@+id/bannerLogo" android:layout_above="@+id/cspinner"></ImageView>
<Button android:id="@+id/buttonGo" android:layout_width="fill_parent" android:text="@string/btnRun" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true"></Button>
</RelativeLayout>
</ScrollView>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试为横向模式制作单独的布局并将其放入
try making a separate layout for landscape mode and putting it into
嗯......你给出了一个重要的线索:“在景观中,一切都会缩小以适应”。如果一切都合适,那么没有滚动条是正常的!
因此,我建议将您的relativelayout高度更改为“环绕内容”而不是“填充父级”。这样,如果相对布局中的内容超过滚动视图高度,您将能够滚动。
顺便说一句-此外,填充父级现在已经过时了。您应该使用“匹配父母”来代替!
Hmm... You give an important clue: "In LandScape everything shrinks to fit". If everything fits, it's normal there's no scroll!
So I'd suggest to change your RelativeLayout height to "wrap content" instead of "fill parent". That way, if the contents inside your relativelayout exceed the scrollview height, you will be able to scroll.
BTW- Besides, fill parent is now obsolete. You should be using "match parent" instead!