【问题标题】:cannot put imageview in the scrollview android studio无法将 imageview 放入滚动视图 android studio
【发布时间】:2016-04-11 23:37:58
【问题描述】:

我正在尝试将 imageview 放在 android studio 的滚动视图中,但它不允许我将 imageview 拖放到滚动视图中。

这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ccc"
    android:gravity="center"
    android:orientation="vertical"
    android:paddingTop="30dp">

    <LinearLayout
        android:id="@+id/content"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:background="#ffffff"
        android:gravity="center"
        android:orientation="vertical"
        android:textColor="#ffffff">

        <TextView
            android:id="@+id/homepagetxt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:textColor="#000000"
            android:textStyle="italic" />

    </LinearLayout>


</ScrollView>

我可以将它放在线性布局中,但它会弄乱我的屏幕布局。 但是,我不能像在线性布局结束标记之后那样把它放在滚动视图中。

将imageview放入scrollview有什么限制吗?

感谢您的友好回应。

【问题讨论】:

    标签: android android-studio


    【解决方案1】:

    一个 ScrollView 只能有一个直接子级。如果要在其中放置多个视图,则必须将这些视图放在 LinearLayout 或 RelativeLayout 中。

    Scrollview can host only one direct child

    【讨论】:

    • 哦.. 我可以有一个包含另一个线性布局和滚动视图的线性布局吗?
    • 是的,因为线性(或相对)布局可以包含多个直接子级,但滚动视图只能有一个直接子级。
    【解决方案2】:

    将imageview放入scrollview有什么限制吗?

    没有。但是,ScrollView 只能有一个孩子。目前,那是你的LinearLayout

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-06
      • 1970-01-01
      相关资源
      最近更新 更多