在LinearLayout中将Imageview放在Imageview上

xso*_*onz 2 css android image android-layout

我坚持使用一些xml代码,希望你能帮助我.

所以这就是我现在需要的东西/我现在所做的.

我有3张650px宽的图像,我需要它们一个在另一个下方,同时保持宽高比.

我用以下代码完成了它,看起来应该如此.这里没问题.

<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"/>
Run Code Online (Sandbox Code Playgroud)

问题是.我需要在每个图像的左下角放置三个textview.想象一下它就像每个图像上带有文字描述的图像菜单.

所以,我不能使用相对或框架布局,因为图像不能很好地相互玩耍:)总是有一个差距,不是宽高比等等.我需要权重.

其次,我不能在photoshop中对每个图像上的文本进行硬编码,因为应用程序将被翻译,并且文本需要针对每种语言进行更改.

我可以为每种语言提供不同的图像,但我试图避免这种情况.

啊,是的,还有一件事.我尝试将整个线性布局放在相对布局中并将文本放在两者之间,但文本显示在图像下方,我无法预先显示它.

有什么建议?

非常感谢,Xsonz

Kas*_*haj 13

只需复制一下:

<?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>
Run Code Online (Sandbox Code Playgroud)