android - 如何在 Android Studio 中将 alpha 属性设置为图像而不是文本?
问题描述
我使用线性布局来平均分布视图组的空间。我将视图组背景设置为图像并将 alpha 属性添加到线性布局。不透明度应用于视图组中的所有视图。但我希望 alpha 属性应仅应用于背景图像而不应用于 textview。有没有办法在线性布局中做到这一点。
<LinearLayout
android:layout_height="300dp"
android:layout_width="match_parent"
android:layout_below="@id/getCoffeeText"
android:background="@drawable/coffee"
android:layout_marginLeft="20sp"
android:layout_marginRight="20sp"
android:alpha="0.5"
android:layout_centerHorizontal="true"
android:layout_marginTop="20sp"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Order Coffee Here....!!!!"
android:textColor="#D50000"
android:textSize="20sp"
android:layout_marginLeft="60sp"/>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal">
<Button
android:text="+"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:onClick="incrementCoffeeCount"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:padding="45sp"
android:text="0"
android:textSize="20sp"
android:textColor="#D50000"
android:id="@+id/coffeeCount"
/>
<Button
android:text="-"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:onClick="decrementCoffeeCount"
/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Price"
android:textSize="25sp"
android:textColor="#D50000"
android:layout_marginLeft="130sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="$0"
android:textSize="20sp"
android:textColor="#D50000"
android:layout_marginLeft="130sp"
android:id="@+id/price"/>
<Button
android:text="Order"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginLeft="110sp"
android:onClick="submitOrder"/>
</LinearLayout>
我想在linearlayout而不是Relativelayout中执行此操作。任何人请帮助我。在此先感谢。
解决方案
尝试使用FrameLayout
如下代码:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.5"
android:layout_gravity="center"
android:background="@drawable/coffee" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Hello World!"
android:textColor="@color/orange"
android:textSize="30sp" />
</LinearLayout>
</FrameLayout>
推荐阅读
- python - 如何根据文件夹名称将文件从一个带有子文件夹的目录复制到另一个带有子文件夹的目录?
- javascript - 如何在执行代码时将数据发送到javascript
- sql-agent-job - 如何强制无限循环脚本在 sql server 代理作业中停止
- google-apps-script - 对 directory.members.insert 的 API 调用失败并出现错误:成员已存在
- android - Android 模拟器上的密钥库崩溃
- c# - 是否有一种线程安全的方法来复制装饰对象的事件处理程序?
- dotnetnuke - 外部 URL 页面 DNN9 的权限不起作用
- typescript - 使用 Getter 和 Setter 计算的 Vue 属性不会在 Webpack 中编译
- proxy - 如何设置 FiddlerCore 以监控所有系统流量?
- ruby-on-rails - 使用 Google Cloud App Engine 部署时如何修复“捆绑程序:找不到命令:rails”