[英]How to draw angled rectangle as background for ViewPager android
我想實現一個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>
誰能告訴我該怎么做?
如果您需要學習如何創建對角線切口,可以看一下本教程: https : //medium.com/@adinugroho/create-diagonal-cut-view-in-android-5a376eca6a1c
如果您需要一個庫來為您做這件事,那么看看這個庫: https : //github.com/florent37/DiagonalLayout
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.