【问题标题】:ScrollView layout or its RelativeLayout parent is possibly uselessScrollView 布局或其 RelativeLayout 父级可能没用
【发布时间】:2016-04-01 19:16:47
【问题描述】:

我正在开发 Android 4 及更高版本的应用程序。 一层生成此警告:此ScrollView 布局或其RelativeLayout 父级可能无用;将背景属性转移到另一个视图

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

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="3dp" >

        <WebView
            android:id="@+id/about"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"         
            android:layerType="software" />
    </ScrollView>

</RelativeLayout>

我该如何解决这个警告?

【问题讨论】:

  • 如果以下任何答案回答了您的问题,请将其标记为答案。

标签: android


【解决方案1】:

这个错误意味着RelativeLayout没有用,因为它只包含一个View(ScrollView)。您应该将 ScrollView 设为父级,记住将 xmlns:android 标记以及 #000 背景属性移动到 ScrollView。这将提高性能并应消除错误。还要记住,一个 ScrollView 应该只有一个子视图。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000"
    android:layout_marginBottom="3dp" >

    <WebView
        android:id="@+id/about"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"         
        android:layerType="software" />
</ScrollView>

【讨论】:

    【解决方案2】:

    通常,您希望 ScrollView 在外面,它允许您滚动您拥有的内容。

    我想这就是你想要的:

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="3dp" >
    
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#000"
            android:orientation="vertical" >
    
        <WebView
            android:id="@+id/about"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"         
            android:layerType="software" />
    
        </RelativeLayout>
    </ScrollView>
    

    【讨论】:

      【解决方案3】:

      如果您真的想使用相对或线性布局,您可以在线性布局之后提供的 Scrollview 之前使用,您将不得不使用任何控件(Imageview、Imagebutton 等),那么它不会引发任何警告/错误。

      愉快的编码

      【讨论】:

      • 这应该是评论
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-06
      • 1970-01-01
      相关资源
      最近更新 更多