在视图上覆盖颜色



我正面临一个视图背景覆盖的特定问题。我做了一个简单的例子项目来展示我的问题我有两个相同大小的视图。另外,两个视图都有带角半径的背景渐变绘制。xml

<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"
tools:context=".MainActivity">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="100dp">
<View
android:id="@+id/view_1"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<View
android:id="@+id/view_2"
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:layout_height="match_parent"/>

</FrameLayout>

和我的mainActivity

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val view1 = findViewById<View>(R.id.view_1)
val view2 = findViewById<View>(R.id.view_2)
val bg1 = GradientDrawable().apply {
setColor(Color.BLUE)
cornerRadius = 20.toPxF()
}
val bg2 = GradientDrawable().apply {
setColor(Color.RED)
cornerRadius = 20.toPxF()
}
view1.background = bg1
view2.background = bg2
}
}

我所看到的全屏全屏

也有圆角颜色之间的过渡

最高

底部实际上我不想看到圆角的颜色变化(颜色叠加)。

我怎样才能做到这一点?

更新:我为第二个渐变绘制添加了笔画我看到边缘颜色变平滑了。我还尝试为第二个视图(红色)添加描边,并将其直接放置在第一个视图(蓝色)的上方点击

我想要类似的点击底部边界有相同的坐标,两个视图有相同的舍入

我可以详细说明这个主题几个小时,但简而言之:你想要这种效果。至少在你的视野中是这样的。底部看起来不太好,但是你可以加上layout_marginBottom,对吧?作业:阅读抗锯齿

最新更新