Christian
Christian

Reputation: 11

Make ImageView fit exactly the size of TextViews

I'm relatively new to Android development, so please don't be too harsh with me ;)

I've read quite a lot about different image sizes and layouts for different devices, but this doesn't seem to help me a lot with my problem.

I want to create a maths app including vectors and for these I want to display three TextViews for the coordinates and the typical brackets around them. For the brackets I certainly have to use ImageViews, but I don't find a way to put the image into the exactly right position and give it the exactly fitting size for the TextViews next to it.

The image below shows a snippet, which hopefully shows quite clearly, what I mean. It's an extreme example, I've already got a quite good result with a different image size, but this doesn't work on another device with a different resolution. By the way, I used a RelativeLayout for this.

snippet of the app showing an ugly vector

Is there any foolproof way to make sure that the vector is portrayed correctly on any given device? I hope, this question isn't too stupid!

Upvotes: 0

Views: 91

Answers (1)

Vishal Makasana
Vishal Makasana

Reputation: 960

 <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
   >

    <ImageView
        android:id="@+id/yourImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/textLayout"
        android:layout_alignTop="@+id/textLayout"
        android:src="@drawable/curly"
        android:adjustViewBounds="true" />

    <LinearLayout
        android:id="@+id/textLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="10dp"
        android:paddingBottom="10dp"
        android:layout_toRightOf="@+id/yourImage"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="AAA" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="BBB" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="CCC" />

    </LinearLayout>

</RelativeLayout>

find the result of above code in below image

enter image description here

Upvotes: 1

Related Questions