[英]How can I achieve the view like below image? I want to make the view from xml using Roatation
Please help I already do like the view like screenshot 2 but having a problem to achieve like screenshot 1.Is it possible to do?请帮助我已经喜欢屏幕截图 2 的视图,但在实现屏幕截图 1 时遇到问题。是否可以这样做?
View with rotation with feel the screen.旋转查看,感受屏幕。
Thanks in advance.提前致谢。
<?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"
android:background="@color/accent_material_dark"
android:orientation="vertical">
<View
android:id="@+id/header"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:background="#FFFFFF" />
<View
android:id="@+id/body"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_below="@id/header"
android:rotation="165"
android:background="@color/accent_material_dark" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/header"
android:layout_alignParentRight="true"
android:src="@drawable/ic_action_search"
android:layout_marginBottom="-32dp"
android:layout_marginRight="20dp">
</android.support.design.widget.FloatingActionButton>
</RelativeLayout>
I should say that what you're trying to accomplish would be best achieved with a background drawable with the shape you want, rather than trying to rotate views to look like this.我应该说,您想要完成的工作最好使用具有您想要的形状的可绘制背景来实现,而不是尝试旋转视图以使其看起来像这样。 It's simply a lot of work and views to achieve something that a basic knowledge in microsoft paint would achieve as well.
只需大量的工作和视图即可实现 microsoft Paint 的基本知识也可以实现的目标。
That being said, to get your desired result, you just need to apply the pivot points of the view you're rotating to the top left corner (0, 0), and rotate only 15 degrees in the opposite direction"话虽如此,为了获得您想要的结果,您只需要将您旋转的视图的轴心点应用到左上角 (0, 0),并在相反方向仅旋转 15 度”
<View
android:id="@+id/body"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_below="@id/header"
android:transformPivotX="0dp"
android:transformPivotY="0dp"
android:rotation="-15"
android:background="@color/accent_material_dark" />
You might also need to make the view a bit longer, since the rotation will mean the view doesn't extend to the edge of the screen (due to pythagorean's theorem).您可能还需要使视图更长一点,因为旋转将意味着视图不会延伸到屏幕的边缘(由于勾股定理)。 You could do this by applying a large dp value for the view's width, or by setting the view's scaleX property to 1.5, or something similar.
你可以通过为视图的宽度应用一个大的 dp 值,或者通过将视图的 scaleX 属性设置为 1.5 或类似的东西来做到这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.