如何防止其他视图被推出屏幕(How to prevent other View being pushed out of the screen)

编程入门 行业动态 更新时间:2024-10-23 16:14:48
如何防止其他视图被推出屏幕(How to prevent other View being pushed out of the screen)

这是XML示例

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_margin="5dip" android:background="#FF992222"> <ScrollView android:layout_height="wrap_content" android:layout_width="fill_parent"> <LinearLayout android:layout_height="wrap_content" android:orientation="vertical" android:layout_width="fill_parent"> <TextView android:layout_width="wrap_content" android:text="TextView" android:layout_height="wrap_content" android:textSize="24dip"></TextView> </LinearLayout> </ScrollView> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_margin="5dip" android:background="#FF555555"> <TextView android:layout_width="wrap_content" android:text="TextView" android:layout_height="wrap_content" android:textSize="24dip"></TextView> </LinearLayout> </LinearLayout>

结果是这样的:

如果你注意到,上层LinerLayout中的文本被包裹在LinearLayout和ScrollView中。

如果上面的内容保持添加,它将看起来像这样

底部Linearlayout将在ScrollView变为活动状态之前被推出屏幕,并使第一个内容变成可滚动的....并且我不希望发生这种情况......

我应该做些什么才能使底部视图之前的滚动视图像这样被推出屏幕:

(这是编辑的图像,不是由Android布局编辑器创建的)

希望这个问题清楚。谢谢:)

this is the example XML

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_margin="5dip" android:background="#FF992222"> <ScrollView android:layout_height="wrap_content" android:layout_width="fill_parent"> <LinearLayout android:layout_height="wrap_content" android:orientation="vertical" android:layout_width="fill_parent"> <TextView android:layout_width="wrap_content" android:text="TextView" android:layout_height="wrap_content" android:textSize="24dip"></TextView> </LinearLayout> </ScrollView> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_margin="5dip" android:background="#FF555555"> <TextView android:layout_width="wrap_content" android:text="TextView" android:layout_height="wrap_content" android:textSize="24dip"></TextView> </LinearLayout> </LinearLayout>

The result is like this :

If you notice, the text in upper LinerLayout are wrapped in LinearLayout and ScrollView.

If the upper content keep added, it will look like this

Bottom Linearlayout will be pushed out of the screen before the ScrollView become active and make the first content become scrollable.... And I don't want that to be happened...

What should I do to make the Scrollview before the bottom View being pushed out of the screen like this :

(this is edited image and not created by Android Layout editor)

Hope the question clear enough.. Thanks :)

最满意答案

那么,如果我清楚地理解了你的问题,那么你希望TextView以灰色保持静止,而红色的textViews可以滚动,如果我在这里错了,请纠正我。 如果这就是你想要的,那么你可以使用RelativeLayout来实现。 以下是生成如下输出的代码: http://imageshack.us/photo/my-images/836/device20111011012652.png/ ListView条目是可滚动的,而按钮(在你的情况下它应该是一个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"> <ListView android:id="@android:id/list" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/newtask" android:layout_alignParentTop="true"> </ListView> <Button android:layout_width="fill_parent" android:id="@+id/newtask" android:layout_height="wrap_content" android:text="Add New Task" android:layout_alignParentBottom="true"> </Button> </RelativeLayout>

只需将底部按钮更改为TextView,它就可以匹配您想要的内容。

Well, if I understand you question clearly, you want the TextView in grey to remain stationary, while the textViews in red can be scrolled around, correct me if I'm wrong here. If thats what you want, then you can use RelativeLayout to achieve that. Following is the code to produce an output like: http://imageshack.us/photo/my-images/836/device20111011012652.png/ The ListView entries are scrollable while the button(in your case it should be a TextView) stays where it is.

Code:

<?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"> <ListView android:id="@android:id/list" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/newtask" android:layout_alignParentTop="true"> </ListView> <Button android:layout_width="fill_parent" android:id="@+id/newtask" android:layout_height="wrap_content" android:text="Add New Task" android:layout_alignParentBottom="true"> </Button> </RelativeLayout>

Just change the bottom button to a TextView and it would match what you wanted.

更多推荐

本文发布于:2023-07-08 20:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1080282.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   如何防止   屏幕   prevent   pushed

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!