图像和文字的透明度

问题描述 投票:0回答:2

我希望在android中显示我的项目图像和标题这种格式我有一个预览这种格式的漂亮样本图像请参阅我的样本图像My sample image

我正在使用此代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.testforme.android.sample.ItemListActivity">


<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="8dp"
    android:background="#FFF" >

    <ImageView
        android:id="@+id/article_img"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        android:src="@drawable/item_img"
        />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="#7000"
        android:orientation="vertical"
        android:paddingBottom="15dp"
        android:paddingTop="15dp" >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:shadowColor="#000"
            android:shadowDx="3"
            android:shadowDy="3"
            android:shadowRadius="6"
            android:text="Styling Android"
            android:textColor="#FFF"
            android:textSize="36sp"
            android:textStyle="bold" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="A guide to applying styles and themes to Android apps"
            android:textColor="#CCC"
            android:textSize="12sp"/>
    </LinearLayout>
</RelativeLayout>



</LinearLayout>

但我的结果是: My result image

如何将图像和文本设置为示例图像?

android textview imageview styles
2个回答
1
投票

与样品:)和FLATTENED相同

 <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
                                                 xmlns:app="http://schemas.android.com/apk/res-auto"
                                                 xmlns:tools="http://schemas.android.com/tools"
                                                 android:id="@+id/frameLayout"
                                                 android:layout_width="match_parent"
                                                 android:layout_height="match_parent">

<ImageView
    android:id="@+id/article_img"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/item_img"/>


        <TextView
            android:layout_above="@+id/lower_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/bg_grey"
            android:gravity="center"
            android:shadowColor="#000"
            android:shadowDx="3"
            android:shadowDy="3"
            android:shadowRadius="6"
            android:text="Styling Android"
            android:textColor="#FFF"
            android:textSize="36sp"
            android:textStyle="bold"/>

        <TextView
            android:layout_marginBottom="4dp"
            android:id="@+id/lower_text"
            android:layout_alignParentBottom="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/bg_grey"
            android:gravity="center"
            android:text="A guide to applying styles and themes to Android apps"
            android:textColor="#CCC"
            android:textSize="12sp"/>
    </RelativeLayout>

和drawable bg_grey.xml代码

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#a2515350"/>
        </shape>
    </item>
</selector>

0
投票

试试这个:

  <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="8dp"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/article_img"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        android:src="@drawable/item_img" />

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">

        <view
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:alpha="0.4"
            android:background="#7000" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingBottom="15dp"
            android:paddingTop="15dp">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:shadowColor="#000"
                android:shadowDx="3"
                android:shadowDy="3"
                android:shadowRadius="6"
                android:text="Styling Android"
                android:textColor="#FFF"
                android:textSize="36sp"
                android:textStyle="bold" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="A guide to applying styles and themes to Android apps"
                android:textColor="#CCC"
                android:textSize="12sp" />
        </LinearLayout>
    </FrameLayout>
</RelativeLayout>
© www.soinside.com 2019 - 2024. All rights reserved.