relativelayout设计问题:relativelayout和button之间的scrollview
我的 Activity 的布局必须如下所示:
- 屏幕分为 3 个部分(3 个“行”),
- 第一个部分由左侧的图像和旁边的两个 TextView 组成。
- 第二部分是一个大文本,放入 ScrollView 中以便可以滚动。
- 第三部分只是一个按钮,并且该按钮必须始终位于屏幕底部。
因此,第 1 部分和第 3 部分都必须固定,只有第 2 部分可以滚动。
这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout0"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/imageView1"
android:text="TextView" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/imageView1"
android:layout_below="@id/textView1"
android:text="TextView" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/relativeLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/relativeLayout1">
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text " />
</ScrollView>
</RelativeLayout>
<RelativeLayout
android:id="@+id/relativeLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/relativeLayout2">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</RelativeLayout>
</RelativeLayout>
这里的问题非常明显:
中间部分的文本可以滚动,但问题是当按钮在布局中“开始”时,ScrollView 不会“结束”。
The layout of my activity must be as follows:
- screen is divided into 3 sections (3 "rows")
- first section consists of an image to the left, and two TextViews next to it.
- second section is a large text, put into a ScrollView so it can be scrolled.
- third section is just a button, and this button must be at the bottom of the screen always.
So, both the 1st and 3rd sections must be fixed, only the 2nd section can be scrolled.
Here is my code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout0"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/imageView1"
android:text="TextView" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/imageView1"
android:layout_below="@id/textView1"
android:text="TextView" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/relativeLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/relativeLayout1">
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text BIG BIG text " />
</ScrollView>
</RelativeLayout>
<RelativeLayout
android:id="@+id/relativeLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/relativeLayout2">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</RelativeLayout>
</RelativeLayout>
The problem is pretty obvious here:
The text in the middle section can be scrolled alright, but the problem is the fact that the ScrollView doesn't "end" when the button "begins" in the layout.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
Try this:
我想补充一点,您可以使用RelativeLayout 作为最外层布局(而不是Luksprogs 示例中的LinearLayout)来解决此问题。假设您有两个视图:viewAbove 和 viewBelow,并且您想用另一个视图填充两个视图之间的空间。将其添加到后一个视图中:
I'd just like to add that you can solve this using a RelativeLayout as the outermost layout (instead of LinearLayout as in Luksprogs example). Lets say you have two views: viewAbove and viewBelow, and you want to fill the space between the two views with another view. Add this to the latter view: