布局底部带有透明标题的Android ImageView

标签 android android-layout android-linearlayout

我有一个带有 ImageView 和 TextView 的布局。

我想要这样的东西:

enter image description here

带有标题的 ImageView ,但我希望标题的布局是透明的,以便在背景中显示 ImageView 。

这是我的布局代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="230dp"
        android:layout_marginBottom="3dp" >

        <ImageView
            android:id="@+id/imgimg"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:src="@drawable/ic_action_picture"
            android:scaleType="centerCrop" />

        <TextView
            android:id="@+id/titlenew"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:text="TextView"
            android:textColor="@color/blanc" />

    </RelativeLayout>

</LinearLayout>

最佳答案

试试这个

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="230dp"
    android:layout_marginBottom="3dp" >

    <ImageView
        android:id="@+id/imgimg"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="centerCrop"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/titlenew"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="#80000000"
        android:gravity="center"
        android:padding="5dp"
        android:text="TextView"
        android:textColor="#fff" />
</RelativeLayout>

enter image description here

关于布局底部带有透明标题的Android ImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18309327/

相关文章:

android - 在 Android 相机上拍照,无需点击按钮或屏幕

android - 如何使按钮在布局中右对齐?

android - 你如何根据 SQLite 文档调整 Android 的 SQLite,例如杂注缓存大小?

java - 将主题应用于 AlertDialog Builder 会导致标题无法正常工作

android - 在TabLayout下的AppBarLayout中添加自定义阴影?

android - 如何在activity类中使用自定义类(扩展View类)来绘制路径而不改变android中主布局的其他部分

java - Android - LinearLayout不添加自定义 View

Android:Facebook 菜单在列表滚动中显示和 Conceal

java - 在 Fragment 的 onActivityCreated() 之前调用 Activity onStart()

android - 适配器中的膨胀布局忽略大小