我卡在了一些 xml 代码中,希望你能帮助我。
这就是我现在需要的/我已经完成的。
我有 3 张宽度为 650 像素的图片,我需要在保持纵横比的情况下将它们一张放在另一张下面。
我用下面的代码做到了这一点,它看起来应该如此。这里没问题。
<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"/>
问题是。我需要在每张图片的左下角放置三个 TextView 。把它想象成图像菜单,每张图像上都有文字描述。
所以,我不能使用相对或框架布局,因为图像不能很好地相互播放 :) 宽高比等之间总是有差距。我需要权重和。
其次,我无法在 photoshop 中对每张图片上的文本进行硬编码,因为应用程序将被翻译,文本需要针对每种语言进行更改。
我可以为每种语言使用不同的图像,但我正在努力避免这种情况。
啊,是的,还有最后一件事。 我试图将整个线性布局放在相对布局中,并将文本放在它们之间,但文本出现在图像下方,我无法将其放在前面。
有什么建议吗?
非常感谢, Xsonz
最佳答案
只需复制这个:
<?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>
关于android - 在 LinearLayout 中将 textview 放在 Imageview 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28112421/