我想创建一个类似分隔符的视图,该视图会渐变到边缘。因此,我创建了一个可绘制的形状,两边都有渐变,我将其设置为视图的背景。在我的XML预览中,显示了我想要的结果,但当我在模拟器中启动应用程序时,绘图被旋转了90度,我不知道为什么。
这是我的形状
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:centerColor="@color/white"
android:endColor="@color/transparent"
android:startColor="@color/transparent"
android:type="linear" />
</shape>
这是我的观点
<View
android:layout_width="256dp"
android:layout_height="100dp"
android:background="@drawable/horizontal_fading_divider"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/recycler_view"
android:layout_marginTop="40dp"/>
这就是它应该看起来像(预览(
这就是的实际外观
多亏了Nice umang,我找到了答案。
你必须使用角度属性,即使你不想旋转你的形状以确保安全,它不会在其他地方旋转。
像这样
android:angle="0"