展开滚动视图下方的按钮
我尝试实现的布局(我认为)非常简单。
一个 TextView 根据内部内容进行扩展。下面有两个按钮(确定/取消)。
我可以让按钮粘在屏幕底部,效果很好。但我希望这些按钮位于 TextView 下方。 我尝试了很多不同的事情,但这是我最新的布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ScrollView android:id="@+id/Scroll"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
>
<TextView
android:id="@+id/Text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</ScrollView>
<RelativeLayout android:id="@+id/buttons"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_below="@+id/Scroll"
android:layout_above="@+id/bottom"
>
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<Button android:id="@+id/ButtonOK"
android:layout_height="80dp"
android:layout_width="fill_parent"
android:text="OK"
android:layout_weight="1"/>
<Button android:id="@+id/ButtonCancel"
android:layout_height="80dp"
android:layout_width="fill_parent"
android:text="Cancel"
android:layout_weight="1"/>
</LinearLayout>
</RelativeLayout>
<LinearLayout android:id="@+id/bottom"
android:layout_height="0px"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
最后的空线性布局是一种(不成功的)尝试,以防止视图延伸到屏幕底部...
在我尝试的所有操作中,要么按钮位于屏幕底部,否则当 TextView 太大时它们会越过屏幕。
这是我想要做的事情的草图:
The layout I try to implement is (I think) pretty simple.
One TextView expands depending on what is inside. Just below are two buttons (OK/Cancel).
I can make the buttons stick to the bottom of the screen and that works fine. But I would like to have those buttons just below the TextView.
I have tried a lot of different things, but here is my latest layout :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ScrollView android:id="@+id/Scroll"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
>
<TextView
android:id="@+id/Text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</ScrollView>
<RelativeLayout android:id="@+id/buttons"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_below="@+id/Scroll"
android:layout_above="@+id/bottom"
>
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<Button android:id="@+id/ButtonOK"
android:layout_height="80dp"
android:layout_width="fill_parent"
android:text="OK"
android:layout_weight="1"/>
<Button android:id="@+id/ButtonCancel"
android:layout_height="80dp"
android:layout_width="fill_parent"
android:text="Cancel"
android:layout_weight="1"/>
</LinearLayout>
</RelativeLayout>
<LinearLayout android:id="@+id/bottom"
android:layout_height="0px"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
The empty linearlayout at the end is an (unsuccessful) attempt to prevent the view to extend past the bottom of the screen...
In everything I tried, either the buttons are at the bottom of the screen or they would go past it when the TextView is too big.
Here is a sketch of what I am trying to do :
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
目标只是拥有一个占据整个页面的可滚动区域减去底部某些按钮所占据的量吗?
如果是这种情况,您可以在外层使用 LinearLayout 并利用权重:
Is the goal just to have a scrollable area that takes up the entire page minus the amount taken up by some buttons at the bottom?
If that's the case, you can use a
LinearLayout
at the outer level and make use of weights:这应该是 xml 中的答案
http://www.curious -creature.org/2010/08/15/scrollviews-handy-trick/
This should be the answer in xml
http://www.curious-creature.org/2010/08/15/scrollviews-handy-trick/
我发现这个链接对我确实有帮助。
http://www.droidnova.com/layout-technique -static-elements-below-scrollview,123.html
我对键盘解决方案有一些非常具体的定制需求——要求我自己作为 z 层处理键盘的显示和拆卸框架布局中的元素。我使用该链接中的解决方案来完成此任务,并同时更改滚动视图的大小。滚动视图中的按钮从与屏幕底部齐平移动到与键盘顶部齐平。
关键是在滚动视图上设置 android:fillViewport="true" 。然后以编程方式将滚动视图的下边距设置为 -height,将底部元素的上边距设置为 -height。
这是我处理它的两种方法:
I found this link that really helped me.
http://www.droidnova.com/layout-technique-static-elements-below-scrollview,123.html
I have some very specific customized needs for a keyboard solution -- requiring me to handle the display and tear-down of the keyboard on my own as a z-layer element in a frameLayout. I use the solution in that link to accomplish that and change the size of the scrollView at the same time. The buttons in the scroll view move from flush with the bottom of the screen to flush with the top of the keyboard.
The key is having android:fillViewport="true" on the scrollView. Then programmatically setting the bottom margin of the scrollView to and the top margin of the bottom element to -height.
Here's my two methods that handle it:
希望有帮助
Hope it helps
这个 xml 对于我的应用程序来说没问题:
This xml is ok for my app: