Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Put a textview over Imageview in LinearLayout

I have stuck in some xml code and i hope you can help me out.

So here is what I need/what I have done by now.

I have 3 images of 650px width and I need them one below another while keeping aspect ratio.

I did that with the following code and it looks as it should. No problem here.

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ll"
android:orientation="vertical"
android:background="#3afa3f"
android:weightSum="3">

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/krk_history"
    android:layout_weight="1"
    android:background="@drawable/povjestkrka_vintage_yellow600" />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:id="@+id/krk_frankopan"
    android:background="@drawable/frankopan2_vintage_sundown600" />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:id="@+id/krk_turizam"
    android:background="@drawable/krk_turizam_vintage"/>

The problem is. I need to put three textviews in a left bottom corner of each image. Imagine it like image menu with text description on each image.

So, I can not use relative or frame layout because images won't play nicely with each other :) There is always a gap between or not aspect ration etc. I need weightsum.

Second, I can't hardcode the text on each image in photoshop because the app will be translated and text needs to change for each language.

I can have different images for each language but I am trying to avoid that.

Ah yea, one more last thing. I tried to put entire linearlayout in relative layout and put the text between but the text appears beneath the image and I can't bring it upfront.

Any suggestions?

Thanks a lot, Xsonz

like image 365
xsonz Avatar asked Dec 06 '22 23:12

xsonz


1 Answers

just copy this :

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">


<FrameLayout android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left|bottom"
        android:padding="5dp"
        android:text="Text 1" />

</FrameLayout>
 <FrameLayout android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left|bottom"
        android:padding="5dp"
        android:text="Text 2" />

</FrameLayout>
 <FrameLayout android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">

    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left|bottom"
        android:padding="5dp"
        android:text="Text 3" />

</FrameLayout>

like image 182
Kastriot Dreshaj Avatar answered Dec 27 '22 02:12

Kastriot Dreshaj