Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 滚动视图中的相对布局不工作_Android_Scrollview_Android Relativelayout - Fatal编程技术网

Android 滚动视图中的相对布局不工作

Android 滚动视图中的相对布局不工作,android,scrollview,android-relativelayout,Android,Scrollview,Android Relativelayout,我正在尝试将滚动视图设置为相对布局。在这里,上部和底部布局的某些部分将保持不变。所以我在里面使用了另外一个布局,其中有需要滚动的项目 但这根本没有发生,而且屏幕看起来很糟糕。我在定义滚动视图的部分的底部有一些黑色空间 这是我的xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:

我正在尝试将滚动视图设置为相对布局。在这里,上部和底部布局的某些部分将保持不变。所以我在里面使用了另外一个布局,其中有需要滚动的项目

但这根本没有发生,而且屏幕看起来很糟糕。我在定义滚动视图的部分的底部有一些黑色空间

这是我的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>


对此有什么答案吗?

根据您对问题的描述,您的ScrollView高度应该是fillParent

将ScrollView高度设置为wrap\u内容或fill\u parent不会有太大区别。 试一试


我认为出现问题的原因是试图在
ScrollView
中包含
ListView
,因此这里有一个没有ScrollView的解决方案:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/logoTop"
        android:layout_below="@+id/logoTop"
        android:text="TextView" >
    </TextView>

    <ImageView
        android:id="@+id/logoTop"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:scaleType="fitXY"
        android:src="@drawable/logotop" >
    </ImageView>

    <ImageView
        android:id="@+id/barDown"
        android:layout_width="match_parent"
        android:layout_height="40dip"
        android:layout_alignParentBottom="true"
        android:scaleType="fitXY"
        android:src="@drawable/bardown" >
    </ImageView>

    <ImageButton
        android:id="@+id/btnMap"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerInParent="true"
        android:background="@drawable/mapselector"
        android:scaleType="fitXY"
        android:src="@drawable/map" >
    </ImageButton>

    <ImageView
        android:id="@+id/abtHome"
        android:layout_width="match_parent"
        android:layout_height="230dip"
        android:layout_below="@+id/logoTop"
        android:maxWidth="230dip"
        android:scaleType="fitXY"
        android:src="@drawable/abouthome" >
    </ImageView>

    <ImageButton
        android:id="@+id/utBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/barDown"
        android:layout_marginRight="10dip"
        android:layout_marginTop="3dip"
        android:background="@drawable/utilitiesicon"
        android:scaleType="fitXY"
        android:src="@drawable/utilityselector" >
    </ImageButton>

    <TextView
        android:id="@+id/tourcity"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/tourList"
        android:layout_centerHorizontal="true"
        android:background="#80000000"
        android:editable="false"
        android:gravity="center"
        android:paddingBottom="5dip"
        android:paddingTop="5dip"
        android:textColor="@color/white"
        android:textSize="25dip" >
    </TextView>

    <ListView
        android:id="@+id/tourList"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/barDown"
        android:layout_below="@+id/abtHome"
        android:layout_centerInParent="true"
        android:background="#FFFFFF"
        android:cacheColorHint="#00000000"
        android:fadingEdge="horizontal"
        android:fastScrollEnabled="true"
        android:isScrollContainer="false"
        android:scrollbars="none"
        android:visibility="visible" >
    </ListView>

    <ImageButton
        android:id="@+id/btnBack"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/barDown"
        android:layout_marginLeft="10dip"
        android:layout_marginTop="6dip"
        android:background="@drawable/arrowleft"
        android:src="@drawable/arrowselector" >
    </ImageButton>

</RelativeLayout>


因为我没有所有的资源,我无法真正看到它的外观,但我想您可以根据需要调整视图的布局设置。

您的布局非常混乱。。。 至少,我可以区分以下观察结果:

  • 使用了相互冲突的标记。 例如,在“btnMap”元素中:

  • 内部层的元素与高级层的元素对齐。 例如,位于ScrollView内部的“abtHome”与位于上层的“logoTop”对齐(与ScrollView相同)
  • ListView在ScrollView中使用。如果要添加ListView视图的顶部或底部(与ListView项目不同,但必须与ListView项目一起滚动),则必须使用ListView的和方法
一般忠告: 更好地构造标记。确定最高抽象级别的主要元素,然后填充它们

在你的情况下,我会这样做(如果我正确理解你想要实现的目标):

这只是布局和视图组的骨架,您必须用更合适的容器替换

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ViewGroup
        android:layout_width="match_parent"
        android:layout_height="80dp">

        <!-- logoTop here -->
    </ViewGroup>

    <ViewGroup
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <!-- ListView and maybe some overlaying views here -->
    </ViewGroup>

    <ViewGroup
        android:layout_width="match_parent"
        android:layout_height="80dp">

        <!-- barDown here -->
    </ViewGroup>
</LinearLayout>

我解决了这个问题。将列表视图放在滚动视图中是不好的。所以我所做的是,在一个xml中放置一个文本视图和图像视图,并在列表适配器中对其进行膨胀

我将这两个字段放在另一个xml中,比如listbox2.xml

 <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> 

<TextView android:id="@+id/tourcity" android:layout_below = "@+id/abtHome"
    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>
如果位置为0,我将在保留上述两个字段的地方扩展这个新xml,否则它将以正常方式继续


希望我的答案很清楚

你能用LinearLayout来代替RelativeLayout吗?你的
列表视图中有多少项
?无论如何,我认为问题可能来自于在
滚动视图
@Adinia中包含一个已经有滚动条的
列表视图
,是的。甚至我也有同样的感觉。如果是这样的话,你有什么建议吗?列表中有3项view@Android杀手,不,这些物品是相对的,所以我不能使用线性布局,我试着包括这个。现在,请注意,屏幕显示的是它应该显示的样子。但是此时,列表视图的默认滚动也被删除。你能详细说明一下“列表视图的默认滚动”吗?顺便说一句,列表视图只有在里面的项目不再适合列表视图区域后才开始滚动。但是这样,布局就不能向右滚动了?我希望在相对布局内的所有文件都能立即滚动,我只能滚动列表。但我希望其他字段也能和listWell一起滚动,很抱歉,但这似乎是不可能的;但是,如果您的列表始终只有3行,您可以使用一个包含3行的TableView!?将图像、图片和表格放在滚动视图中。嘿,我指的是3个字段作为行。行将动态添加到列表视图,这是不固定的。您也可以在TableView中动态添加行,但实现列表的所有功能并不容易。另一个想法是将tourcity文本和abtHome图像设置为列表的页眉/页脚。
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ViewGroup
        android:layout_width="match_parent"
        android:layout_height="80dp">

        <!-- logoTop here -->
    </ViewGroup>

    <ViewGroup
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <!-- ListView and maybe some overlaying views here -->
    </ViewGroup>

    <ViewGroup
        android:layout_width="match_parent"
        android:layout_height="80dp">

        <!-- barDown here -->
    </ViewGroup>
</LinearLayout>
 <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> 

<TextView android:id="@+id/tourcity" android:layout_below = "@+id/abtHome"
    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>
   public View getView(int position, View convertView, ViewGroup parent) {

    if(position == 0) {
        convertView = mInflater.inflate(R.layout.listbox2, null);
        TextView cityLabel = (TextView) convertView.findViewById(R.id.tourcity);
        cityLabel.setText("Some Text");
        return convertView;
    }

    else if (convertView == null || convertView.getTag() == null) {
        convertView = mInflater.inflate(R.layout.listbox, null);
        convertView.setOnClickListener(clickListener);
        holder = new ViewHolder();
        holder.view1 = (TextView) convertView.findViewById(R.id.listText);
        holder.desc = (TextView) convertView.findViewById(R.id.editText1);
        holder.index = (TextView) convertView.findViewById(R.id.index);
        holder.desc.setVisibility(View.GONE);
        holder.priceBtn = (Button) convertView.findViewById(R.id.prcBtn);
        holder.icon = (ImageView) convertView.findViewById(R.id.listIcon);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

        return convertView;
 }