我看到這樣的畫面這是一個意大利車牌模板: 的TextView內的ImageView的
我的應用程序管理工具。我想用CardView
在RecyclerView
中顯示所有用戶的車輛,其中每個CardView
包含一個ImageView
(顯示前一圖像)和一個TextView
,其中包含車牌。但我怎麼能把TextView
放在正確的位置,與ImageView
中顯示的圖像相比?而且,我認爲最糟糕的事情是,我怎麼能夠正確地爲所有屏幕分辨率放置TextView
?
我看到這樣的畫面這是一個意大利車牌模板: 的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