在LinearLayout中在ImageView上放置一个textview [英] Put a textview over Imageview in LinearLayout

查看:163
本文介绍了在LinearLayout中在ImageView上放置一个textview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经停留在一些xml代码,我希望你可以帮助我。



所以这里是我需要/我现在做了什么。 p>

我有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 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 id =@ + id / krk_turizam
android:background =@ drawable / krk_turizam_vintage/>



我需要在每个图像的左下角放置三个文本视图。想象一下,它像每个图像上有文字描述的图像菜单。



所以,我不能使用相对或框架布局,因为图像不会很好地彼此玩:)总是一个之间的差距或不是方面的比率等。我需要weightum。



其次,我不能硬编码的文本在photoshop中的每个图像,因为应用程序将翻译



我可以为每种语言使用不同的图片,但我想避免这种情况。



Ah yea,还有最后一件事。
我试图把整个linearlayout相对布局,并把文本之间,但文字出现在图像下面,我不能把它提前。



任何建议?



感谢很多,
Xsonz

解决方案

just copy this:

 <?xml version =1.0encoding =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>


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

解决方案

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>

这篇关于在LinearLayout中在ImageView上放置一个textview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆