简体   繁体   English

ImageView中的TextView

[英]TextView inside an ImageView

I have this picture which is the template for an italian license plate: 我有这张照片,是意大利车牌的模板: 意大利板块

My app manages vehicles. 我的应用管理车辆。 I've thought to display all user's vehicles in a RecyclerView with CardView , where each CardView contains an ImageView (which displays the previous image) and a TextView , which contains the license plate. 我曾想过用CardViewRecyclerView显示所有用户的车辆,其中每个CardView包含一个ImageView (显示上一个图像)和一个包含车牌的TextView But how could I do to put the TextView in the correct position compared to the image displayed in the ImageView ? 但是,与ImageView显示的图像相比,我怎么能将TextView放在正确的位置? And, the worst thing I think, how could I do to place the TextView correctly for all screens resolutions? 而且,我认为最糟糕的是,我怎么能正确地为所有屏幕分辨率放置TextView

I've tried a sample code .. 我试过一个示例代码..

res/layout/numberplate.xml RES /布局/ numberplate.xml

<?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"
android:padding="30dp">

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/background"
    android:orientation="horizontal">

<LinearLayout
    android:layout_margin="10dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <ImageView
        android:layout_width="46dp"
        android:layout_height="46dp"
        android:background="@mipmap/ic_launcher" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="46dp"
        android:layout_marginLeft="20dp"
        android:gravity="center"
        android:text="Number"
        android:textSize="25dp" />
    </LinearLayout>
</LinearLayout>
</LinearLayout>

res/drawable/background.xml RES /抽拉/ background.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#d0d0d0" />
<corners android:radius="5dp" />
<stroke android:color="#202020" android:width="3dp"/>
</shape>

And how it looks like. 它看起来如何。 在此输入图像描述

You can change the values to match the way you want.. Hope this helps.. 您可以更改值以符合您想要的方式。希望这有助于..

You could place both the views in a RelativeLayout and superimpose each other. 您可以将两个视图放在RelativeLayout中并相互叠加。 For example, 例如,

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:padding="30dp">
     <ImageView
         android:layout_width="46dp"
         android:layout_height="46dp"
         android:layout_gravity="center"
         android:background="@drawable/your_numberplate_image" />
     <TextView
         android:layout_width="46dp"
         android:layout_height="46dp"
         android:layout_marginLeft="10dp"
         android:gravity="center"
         android:text="Number"
         android:textSize="25dp" />
</RelativeLayout>

重叠两个视图的最佳方法是使用FrameLayout作为父级,而不是使用FrameLayout子级上的layout_gravity和margin属性来设置它们的位置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM