[英]Android. Adding text over image with effect
世界! 我是一名學生,我正在開發一個關於我的國家的Android應用程序。 我注意到應用程序中的漂亮布局。
在這張圖片中,文本視圖放置在具有美麗背景的圖像底部(一種漸變)我想知道你是否可以幫我弄清楚如何做或顯示方向。 我現在所擁有的只有:row.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginBottom="5dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/medeobase"
android:scaleType="fitXY"
android:id="@+id/place_image"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#AA000000">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medeu"
android:id="@+id/place_id"
android:layout_marginLeft="20dp"
android:layout_marginTop="2dp"
android:textSize="18sp"
android:textColor="@color/colorWhite"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Almaty region"
android:textColor="@color/colorPrimary"
android:layout_marginLeft="20dp"
android:layout_below="@+id/place_id"
android:textSize="12sp"
android:id="@+id/place_id_sub"
/>
</RelativeLayout>
</RelativeLayout>
謝謝!
你能做什么,實際上是使用GradientDrawable
作為持有TextView
的RelativeLayout
的背景。
漸變可能如下所示:
my_custom_drawable.xml :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="90"
android:endColor="@android:color/transparent"
android:startColor="@android:color/black" />
</shape>
然后用漸變替換RelativeLayout
的backgroundcolor,如下所示:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="@drawable/my_custom_gradient.xml">
這將導致:
您需要在GradientDrawable
使用顏色,以滿足您的需求。 我無法告訴你哪種顏色適合你的需要。
您還可以添加centerColor
- 有關更多屬性,請參閱文檔 。
我可能會將字幕textcolor更改為與標題textcolor相同的顏色。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.