的TextView内的ImageView的
问题描述:
我看到这样的画面这是一个意大利车牌模板: 的TextView内的ImageView的
我的应用程序管理工具。我想用CardView
在RecyclerView
中显示所有用户的车辆,其中每个CardView
包含一个ImageView
(显示前一图像)和一个TextView
,其中包含车牌。但我怎么能把TextView
放在正确的位置,与ImageView
中显示的图像相比?而且,我认为最糟糕的事情是,我怎么能够正确地为所有屏幕分辨率放置TextView
?
答
我已经尝试了样本代码..
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 /绘制/ 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>
您可以将值更改为你所希望的方式匹配.. 希望这有助于..
Bonus content!!(如果你想..)
答
跨越两个视图的最佳方法是使用FrameLayout作为父级,而不是使用FrameLayout子级上的layout_gravity和margin属性s来设置它们的位置
答
您可以将两个视图放在RelativeLayout中并相互叠加。例如,
<?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>
https://stackoverflow.com/questions/6931900/programmatically-set-left-drawable-in-a-textview –
你也可以做一个困难的方式。在适当的布局中添加imageview和textview并为布局赋予'stroke'背景。 – Pzy64
@ cricket_007我不明白:如果我需要在这张图片里面写**,我怎么能用'drawableLeft'属性来做这件事? – Clyky