简体   繁体   English

如何在scollview中的图像上方添加textview?

[英]How can i add textview above an image in a scollview?

I'm need to place a textView above a scrollView that have a background image. 我需要将textView放在具有背景图像的scrollView上方。 But i try to place the textView and it moves to other sid or doesn't move with the scroll. 但是我尝试放置textView并将其移动到其他sid或不随滚动移动。

here is my xml. 这是我的xml。

    <ScrollView
        android:id="@+id/horizontalScrollView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >


        <LinearLayout
            android:gravity="top"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <ImageView
                android:id="@+id/imageViewObrazekGeometrie"
                android:layout_width="500dp"
                android:layout_height="777dp"
                android:paddingRight="120dp"
                android:src="@drawable/dataviewer" />

            <TextView
                android:id="@+id/textView4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="TextView" />

        </LinearLayout>
    </ScrollView>

I really don't understand your question correctly but will share where you are going wrong. 我确实无法正确理解您的问题,但会分享您的问题所在。 A scroll view can only hold one child but in your case, your HorizontalScrollView has two children one is LinearLayout and another one is TextView please insert both to one parent layout. 滚动视图只能容纳一个孩子,但在您的情况下,Horizo​​ntalScrollView有两个孩子,一个是LinearLayout,另一个是TextView,请将两者都插入一个父布局。

另一个ScrollView中的ScrollView不起作用,您应该将ScrollView放置为root,然后将LinearLayout放置为ScrollView的直接子级

如果您要先使用TextView,然后再使用ImageView,然后在LinearLayout中先使用TextView,并将方向设置为垂直 ,然后在TextView添加ImageView之后,则需要将它们都放入同一个LinearLayout中,因为ScrollView只能处理直接的单个子对象,这就是原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM