开发者

Overlap views in android?

I have a linearlayout which have a textbox(multiline, nearly 5 lines) and image view. Is it possible to draw a image on textview(overlapping)?

Note: I have to specify the coordinates of the image, which are not static, and may be anywhere above text.

Something like this mockup:

开发者_运维技巧

Overlap views in android?


I think it can be achieved using RelativeLayout.

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <TextView
                android:id="@+id/Textview"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="20dp"
                android:text="@string/Text2display"
                android:textColor="#EEDCAA" />


        <ImageView
            android:id="@+id/choose_img"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="-46dp"
            android:adjustViewBounds="true"
            android:contentDescription="@string/description_logo"
            android:src="@drawable/user2" />

    </RelativeLayout>

By placing the TextView block above the ImageView, it ensures that the image view overlaps the TextView. Now, based on your requirements and position, use the following commands from the link :-

http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html

You can align left right, top and bottom. Use negative values to navigate the ImageView, if ur using align bottom and stuff.. This will make it to overlap. Please let me know if this was helpful

Is there any specific reason for Linear Layout?


You can do this easily using RelativeLayout . You can have an ImageView overlapping TextView Unless there is a specific reason for using LinearLayout .


If you really (really) need to use LinearLayout, you can subclass TextView and override onDraw to draw your image.


In all your xml files, should define the background color for it, it will solve the problem :

Add this android:background="@android:color/black" in to the View tag you defined.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜