滚动视图中的相对布局不起作用
我正在尝试将滚动视图置于相对布局中。这里,上部和下部的布局的某些部分是恒定的。所以我在里面使用了另一种布局,其中包含需要滚动的项目。
但这根本没有发生,而且屏幕看起来也很糟糕。我在定义滚动视图的部分底部出现一些黑色空间。
这是我的 xml,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:id="@+id/textView1" android:layout_below="@+id/logoTop"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:text="TextView" android:layout_alignLeft="@+id/logoTop"></TextView>
<ImageView android:src="@drawable/logotop" android:id="@+id/logoTop"
android:layout_alignParentTop="true" android:layout_width="match_parent"
android:scaleType="fitXY" android:layout_height="wrap_content"></ImageView>
<ImageView android:src="@drawable/bardown" android:id="@+id/barDown"
android:layout_width="match_parent" android:scaleType="fitXY"
android:layout_alignParentBottom="true" android:layout_height="40dip">
</ImageView>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="@+id/btnMap" android:layout_centerInParent="true" android:src="@drawable/map"
android:background="@drawable/mapselector" android:scaleType="fitXY"
android:layout_alignParentBottom="true">
</ImageButton>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="@+id/utBtn" android:background="@drawable/utilitiesicon"
android:scaleType="fitXY" android:layout_alignTop="@+id/barDown" android:src="@drawable/utilityselector"
android:layout_alignParentRight="true" android:layout_marginRight="10dip"
android:layout_marginTop="3dip">
</ImageButton>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/logoTop"
android:layout_above="@+id/barDown"
android:scrollbars="none">
<RelativeLayout android:id="@+id/tour"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:id="@+id/abtHome" android:layout_below="@+id/logoTop"
android:src="@drawable/abouthome" android:scaleType="fitXY"
android:layout_width="match_parent" android:maxWidth="230dip"
android:layout_height="230dip">
</ImageView>
<ListView android:id="@+id/tourList" android:layout_below="@+id/abtHome"
android:scrollbars="none" android:visibility="visible"
android:layout_centerInParent="true" android:layout_above="@+id/barDown"
android:background="#FFFFFF" android:cacheColorHint="#00000000" android:fadingEdge="horizontal"
android:fastScrollEnabled="true" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:isScrollContainer="false">
</ListView>
<TextView android:id="@+id/tourcity" android:layout_above="@+id/tourList"
android:layout_height="wrap_content" android:layout_width="match_parent"
android:textSize="25dip" android:layout_centerHorizontal="true"
android:editable="false" android:paddingTop="5dip" android:textColor="@color/white"
android:paddingBottom="5dip" android:background="#80000000" android:gravity="center"></TextView>
</RelativeLayout>
</ScrollView>
<ImageButton android:src="@drawable/arrowselector"
android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignTop="@+id/barDown"
android:id="@+id/btnBack" android:background="@drawable/arrowleft" android:layout_marginLeft="10dip"
android:layout_marginTop="6dip"></ImageButton>
</RelativeLayout>
有什么答案吗?
I am trying to put a scroll view to relative layout. Here some part of the layout on the upper and bottom part are to be constant. So I'm using one more layout inside,which has items that need to be scrolled.
But this is not at all happening, also the screen looks very bad with this. I am getting some black space in the bottom of the part where I defined scroll view.
Here is my xml,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:id="@+id/textView1" android:layout_below="@+id/logoTop"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:text="TextView" android:layout_alignLeft="@+id/logoTop"></TextView>
<ImageView android:src="@drawable/logotop" android:id="@+id/logoTop"
android:layout_alignParentTop="true" android:layout_width="match_parent"
android:scaleType="fitXY" android:layout_height="wrap_content"></ImageView>
<ImageView android:src="@drawable/bardown" android:id="@+id/barDown"
android:layout_width="match_parent" android:scaleType="fitXY"
android:layout_alignParentBottom="true" android:layout_height="40dip">
</ImageView>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="@+id/btnMap" android:layout_centerInParent="true" android:src="@drawable/map"
android:background="@drawable/mapselector" android:scaleType="fitXY"
android:layout_alignParentBottom="true">
</ImageButton>
<ImageButton
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="@+id/utBtn" android:background="@drawable/utilitiesicon"
android:scaleType="fitXY" android:layout_alignTop="@+id/barDown" android:src="@drawable/utilityselector"
android:layout_alignParentRight="true" android:layout_marginRight="10dip"
android:layout_marginTop="3dip">
</ImageButton>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/logoTop"
android:layout_above="@+id/barDown"
android:scrollbars="none">
<RelativeLayout android:id="@+id/tour"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:id="@+id/abtHome" android:layout_below="@+id/logoTop"
android:src="@drawable/abouthome" android:scaleType="fitXY"
android:layout_width="match_parent" android:maxWidth="230dip"
android:layout_height="230dip">
</ImageView>
<ListView android:id="@+id/tourList" android:layout_below="@+id/abtHome"
android:scrollbars="none" android:visibility="visible"
android:layout_centerInParent="true" android:layout_above="@+id/barDown"
android:background="#FFFFFF" android:cacheColorHint="#00000000" android:fadingEdge="horizontal"
android:fastScrollEnabled="true" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:isScrollContainer="false">
</ListView>
<TextView android:id="@+id/tourcity" android:layout_above="@+id/tourList"
android:layout_height="wrap_content" android:layout_width="match_parent"
android:textSize="25dip" android:layout_centerHorizontal="true"
android:editable="false" android:paddingTop="5dip" android:textColor="@color/white"
android:paddingBottom="5dip" android:background="#80000000" android:gravity="center"></TextView>
</RelativeLayout>
</ScrollView>
<ImageButton android:src="@drawable/arrowselector"
android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignTop="@+id/barDown"
android:id="@+id/btnBack" android:background="@drawable/arrowleft" android:layout_marginLeft="10dip"
android:layout_marginTop="6dip"></ImageButton>
</RelativeLayout>
Any answer for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
将scrollView高度设置为wrap_content或fill_parent不会有太大区别。
尝试
Setting scrollView height to wrap_content or fill_parent wouldn't make much difference.
try
从您对问题的描述来看,您的 ScrollView 高度似乎应该是 fillParent
From the description you have given to your problem, it seems that your ScrollView height should be fillParent
我认为出现问题是因为试图在
ScrollView
中包含ListView
,所以这里有一个没有 ScrollView 的解决方案:因为我没有所有资源,所以我不能确实看到了它的外观,但我想您可以根据需要调整视图的布局设置。
I think the problem occur because trying to include
ListView
inScrollView
, so here is a solution without the ScrollView:Because I don't have all the resources, I can't really see how it looks, but I suppose you can adjust some more the layout settings of the views as you wish.
你的布局很混乱...
至少,我可以区分以下观察结果:
使用了冲突的标签。
例如在“btnMap”元素中:
例如,位于 ScrollView 内部的“abtHome”与位于上层(与 ScrollView 相同)的“logoTop”对齐。
一般建议:
更好地构建标记。确定最高抽象级别的主要元素,然后填充它们。
在你的情况下,我会做这样的事情(如果我正确理解你想要实现的目标):
这只是布局和 ViewGroup 的骨架,你必须用更合适的容器替换。
Your layout is very confusing...
At a minimum, I can distinguish the following observations:
Used conflicting tags.
For example in "btnMap" element:
For example "abtHome", wich located inside ScrollView is aligned with respect to "logoTop", wich located at upper level (at the same as ScrollView).
General advice:
Better structuring a markup. Identify the main elements of the highest level of abstraction, and then fill them.
In your case I would do something like this (if I correctly understand what you wanted to achieve):
This is just skeleton of layout and ViewGroup you must replace with a more appropriate containers.
我解决了这个问题。将列表视图放入滚动视图中并不好。所以我所做的是将 1 个文本视图和图像视图放入一个 xml 中,然后在列表适配器中对其进行扩充。
我将这 2 个字段放在另一个 xml 中,比如 listbox2.xml
现在在我的列表适配器中,正在这样做,
如果位置为 0,我将在保留上述 2 个字段的位置膨胀这个新 xml,否则它会以正常方式继续。
希望我的回答很清楚
I solved the issue. It is not good to fit the list view inside scroll view. So what I did is, placed 1 text view and image view in one xml and inflate that in List Adapter.
I placed these 2 fields in another xml say listbox2.xml
Now inside my list adapter, am doing like this
If the position is 0, I am inflating this new xml where I kept the above 2 fields or else it continues in a normal way.
Hope my answer is clear