CraZyDroiD
CraZyDroiD

Reputation: 7105

android layout justification

I have a image view and text views in my layout and it looks like this

enter image description here

How can i fill the empty space with the text? i have used android:layout_toRightOf="@+id/movie_image" to get the text next to the image but it does not fill the empty space when the image is over.

My code

<RelativeLayout 
            android:id="@+id/upperPart"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            >

    <ImageView
            android:id="@+id/movie_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="5dp"
            android:src="@drawable/ic_launcher"
            android:scaleType="fitXY"/>


    <TextView
        android:id="@+id/title_movie"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_toRightOf="@+id/movie_image"
        android:text="@string/temp_title"
        android:textSize="18dp"
        android:textStyle="bold" />

     <TextView
        android:id="@+id/description_movie"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="5dp"
        android:text="@string/moviedescription"
        android:layout_toRightOf="@+id/movie_image"
        android:layout_below="@+id/title_movie"
        android:textSize="14dp"
         />


     </RelativeLayout>

Upvotes: 0

Views: 92

Answers (5)

Jignesh Jain
Jignesh Jain

Reputation: 1568

Try this,

<RelativeLayout
        android:id="@+id/upperPart"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <LinearLayout
            android:id="@+id/lin_image"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:gravity="center"
            android:orientation="vertical" >

            <ImageView
                android:id="@+id/movie_image"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="left"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="5dp"
                android:background="@drawable/ic_launcher" />
        </LinearLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_toRightOf="@+id/lin_image" >

            <TextView
                android:id="@+id/title_movie"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:text="@string/temp_title"
                android:textSize="18dp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/description_movie"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/title_movie"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="5dp"
                android:text="@string/moviedescription"
                android:textSize="14dp" />
        </RelativeLayout>
    </RelativeLayout>

Upvotes: 0

keshav kowshik
keshav kowshik

Reputation: 2374

To Achieve this, you can use two Text views one which is to the rightOf your ImageView and has the text till the Bottom of Image View. Another text view which will be below the Image view and has a width of match_parent. This will not leave any space. Hope this may help you.

Upvotes: 0

user4571931
user4571931

Reputation:

Android's default TextView is not supported justificatoin.. and spanning with image view..

You need to check below example where you find what you needed for spanning image and text..

How to layout text to flow around an image

Upvotes: 1

Apurva
Apurva

Reputation: 7911

What you want is not possible yet in android. I'd suggest you to make textView scrollable instead.

Add following attributes in <TextView android:id="@+id/title_movie" .../>

android:maxLines = "9"
android:scrollbars = "vertical"

Upvotes: 0

RUKMANI SELVARAJ
RUKMANI SELVARAJ

Reputation: 65

The only best way is to make the edit text first and then keep the image view within it. And the other way is to set two edit text by which the empty spaces can be filled.

Upvotes: 0

Related Questions