gpt4 book ai didi

java - 如何绘制有角度的矩形作为 ViewPager android 的背景

转载 作者:行者123 更新时间:2023-11-30 05:11:24 25 4
gpt4 key购买 nike

我想实现一个 ViewPager,它有一个带角度的矩形作为背景,如图所示。我试图通过将 xml 设置为背景来完成它。但只有当我们在该 xml 本身中提供图像并且我尝试在运行时管理它时,它才会正确显示,然后它不会采用那个有角度的背景。

这是我附加到自定义 viewpager 布局的可绘制对象

<item android:top="300dp"
android:bottom="-300dp"
android:left="0dp"
android:right="-300dp">
<rotate
android:fromDegrees="-10"
android:pivotX="0%"
android:pivotY="100%">
<shape
android:shape="rectangle">
<solid
android:color="@color/white"/>
</shape>
</rotate>

这是自定义的 viewpager 布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">

<RelativeLayout
android:id="@+id/rl_image"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="@drawable/custom_imageview">

</RelativeLayout>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/rl_image"
android:layout_marginLeft="20dp"
android:layout_marginTop="-60dp">

<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/profile_image"
android:layout_width="70dp"
android:layout_height="70dp"
android:src="@drawable/fashion1"
app:civ_border_color="#FFF"
app:civ_border_width="1dp" />

</RelativeLayout>
</RelativeLayout>

This is how it should display

谁能告诉我怎么做?

最佳答案

如果您需要学习如何创建对角线切割,您可以查看本教程: https://medium.com/@adinugroho/create-diagonal-cut-view-in-android-5a376eca6a1c

如果你需要一个库来为你做这件事,那么看看这个库: https://github.com/florent37/DiagonalLayout

关于java - 如何绘制有角度的矩形作为 ViewPager android 的背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53679735/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com