如何解决Android:另一个视图之上的透明视图
我想在另一个视图(地图)的顶部有一个(半)透明视图,可以在其中放置各种元素作为覆盖。在当前设置下,我有两个问题,如下图所示:
a。测试矩形始终显示在底部(作为测试,我希望从顶部开始40dp)
b。视图并不完全透明,我的测试矩形上方有一个灰色区域
我的布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/landmark"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="40dp">
<ImageView
android:id="@+id/box"
android:src = "@drawable/rectangle"
android:layout_alignParentBottom = "true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
活动类别:
class LandmarkActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_landmark)
}
}
清单:
<activity android:name=".LandmarkActivity"
android:launchMode="singleTask"
android:theme="@style/Theme.AppCompat.Dialog"
android:windowSoftInputMode="adjustResize|stateHidden"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
解决方法
尝试此操作,不设置layout_alignParentBottom
并设置适当的上边距
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/landmark"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/box"
android:src = "@drawable/rectangle"
android:layout_marginTop="40dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
ImageView
的{{1}}的大小设置为android:src = "@drawable/rectangle"
,因此此wrap_content
的大小取决于您的可绘制对象。您可以考虑将View
和adjustViewBounds
xml attrs添加到scaleType
,但是如果没有实际的真实ImageView
可绘制对象,很难猜测这会有所帮助
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。