android - 无用的父布局

标签 android css xml android-layout scrollview

<分区>

** 此 ScrollView 布局或其 LinearLayout 父级无用; transfer the background attribute to the other view 没有 sibling 的布局,不是 ScrollView 或根布局,也没有背景,可以删除并将其子项直接移动到父项中以获得更平坦的效果高效的布局层次结构。 **

`

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"

android:padding="10dp"
android:background="#504b4b"
tools:context="com.example.sompod.imageview.MainActivity">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="visible"
    >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_gravity="center"
        >

        <ImageView
            android:id="@+id/p1"
            android:layout_width="260dp"
            android:layout_height="260dp"

            android:layout_marginLeft="25dp"
            android:layout_marginStart="25dp"
            android:contentDescription="@null"
            android:rotation="270"


            android:scaleType="fitXY"
            android:src="@drawable/img_5116"
            />

        <ImageView
            android:id="@+id/p2"
            android:layout_width="300dp"
            android:layout_height="200dp"
            android:layout_marginLeft="15dp"
            android:layout_marginStart="15dp"
            android:layout_marginTop="25dp"
            android:contentDescription="@null"
            android:scaleType="fitXY"
            android:src="@drawable/bdboss" />

        <ImageView
            android:id="@+id/p3"
            android:layout_width="292dp"
            android:layout_height="335dp"
            android:layout_marginLeft="20dp"
            android:layout_marginStart="20dp"
            android:layout_marginTop="30dp"
            android:contentDescription="@null"
            android:rotation="270"
            android:scaleType="fitXY"
            android:src="@drawable/img_5123" />


        <ImageView
            android:id="@+id/p4"
            android:layout_width="225dp"
            android:layout_height="279dp"
            android:layout_marginLeft="25dp"
            android:layout_marginStart="25dp"
            android:layout_marginTop="15dp"
            android:contentDescription="@null"
            android:scaleType="fitXY"
            android:src="@drawable/bestone1" />


    </LinearLayout>

</ScrollView>


</LinearLayout>

`

最佳答案

Parent LinearLayout 没用 - 没有附加值。您可以通过这种简单的方式实现相同的目的:

<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#504b4b"
tools:context="com.example.sompod.imageview.MainActivity">

    <LinearLayout
        android:clipToPadding="false"
        android:padding="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_gravity="center"
        >

        <ImageView
            android:id="@+id/p1"
            android:layout_width="260dp"
            android:layout_height="260dp"

            android:layout_marginLeft="25dp"
            android:layout_marginStart="25dp"
            android:contentDescription="@null"
            android:rotation="270"


            android:scaleType="fitXY"
            android:src="@drawable/img_5116"
            />

        <ImageView
            android:id="@+id/p2"
            android:layout_width="300dp"
            android:layout_height="200dp"
            android:layout_marginLeft="15dp"
            android:layout_marginStart="15dp"
            android:layout_marginTop="25dp"
            android:contentDescription="@null"
            android:scaleType="fitXY"
            android:src="@drawable/bdboss" />

        <ImageView
            android:id="@+id/p3"
            android:layout_width="292dp"
            android:layout_height="335dp"
            android:layout_marginLeft="20dp"
            android:layout_marginStart="20dp"
            android:layout_marginTop="30dp"
            android:contentDescription="@null"
            android:rotation="270"
            android:scaleType="fitXY"
            android:src="@drawable/img_5123" />


        <ImageView
            android:id="@+id/p4"
            android:layout_width="225dp"
            android:layout_height="279dp"
            android:layout_marginLeft="25dp"
            android:layout_marginStart="25dp"
            android:layout_marginTop="15dp"
            android:contentDescription="@null"
            android:scaleType="fitXY"
            android:src="@drawable/bestone1" />

    </LinearLayout>

  </ScrollView>

关于android - 无用的父布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47333751/

上一篇:html - HTML 中的图标未显示在网页上?

下一篇:javascript - "Magnific Popup"悬停打开弹出窗口的 div 时离开

相关文章:

android - 单击按钮时启动服务时出现问题

Java 文件在 Android Studio 编辑器中显示得很奇怪

javascript - 隐藏的溢出在 iPad 中不起作用

css - 我如何在标记中指定我的背景图像

xml - 我如何从 Google Maps API 获取行车时间?

android - 在 5.1 android 设备上绘制路线图时应用程序崩溃的问题

android - SurfaceView 实现 Runnable - 线程不启动

javascript - 使用 Bootstrap 来完成我的显示/隐藏 Accordion

android - 设置 TextView 的背景颜色

html - XHTML 到 XML XSLT 转换