如何在 xml 布局中对齐弯曲图像?是否可以在 java 中以编程方式对齐?
How to align the curved images in a xml layout?Is it possible to align programmatically in java?
以下是我必须在我的项目中实现的图像:
最后它应该是这样的:
帮助将是值得称赞的,并提前感谢。
希望这对您有所帮助。对不起,命名不当。,
<LinearLayout 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" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/dummy"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:visibility="invisible" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/a"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/a"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/a"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.1"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.1"
android:background="@drawable/a"
android:orientation="vertical"
android:visibility="visible" >
</LinearLayout>
<LinearLayout
android:id="@+id/dummy2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:background="@drawable/a"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
<LinearLayout
android:id="@+id/dummy3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/a"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/dummy1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:visibility="invisible" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/a"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/a"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/a"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="50dp"
android:layout_weight="1"
android:orientation="horizontal"
android:visibility="visible" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.8"
android:background="@drawable/c"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/c"
android:orientation="vertical"
android:visibility="visible" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.8"
android:background="@drawable/c"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.8"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/a"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
<LinearLayout
android:id="@+id/LinearLayout04"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/c"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
<LinearLayout
android:id="@+id/LinearLayout02"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/c"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/LinearLayout03"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:visibility="invisible" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/c"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/c"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/c"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:visibility="visible" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2.5"
android:background="@drawable/c"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/c"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2.5"
android:background="@drawable/c"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.05"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/a"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
<LinearLayout
android:id="@+id/LinearLayou"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:background="@drawable/c"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
<LinearLayout
android:id="@+id/LinearL"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:background="@drawable/d"
android:orientation="vertical"
android:visibility="visible" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/Linea"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:visibility="visible" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/c"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/d"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/c"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
您可以使用 RelativeLayout
和 margins/padding
,因为您需要将 images
相加。在这里我用你自己的图片给你一个例子:
(请注意,我手动添加了 width/height
,并不关心 naming
,因为它只是为了测试目的,为您提供有关如何实现它的线索。因此,如果你和 imageViews
的 height/width
一起玩,你也必须和他们的 margins/padding
一起玩)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent">
<ImageView
android:layout_marginLeft="85dp"
android:layout_width="170dp"
android:layout_height="170dp"
android:src="@drawable/tt"
/>
<ImageView
android:layout_marginTop="70dp"
android:layout_width="170dp"
android:layout_height="170dp"
android:src="@drawable/ll"/>
<ImageView
android:layout_marginTop="100dp"
android:layout_marginLeft="90dp"
android:layout_width="170dp"
android:layout_height="170dp"
android:src="@drawable/rr"/>
<TextView
android:gravity="center"
android:layout_marginTop="130dp"
android:layout_marginLeft="100dp"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="This is just a text"/>
</RelativeLayout>
其中:
tt
是上面的曲线
rr
是右边的曲线
ll
是左边的曲线
结果如下:
以下是我必须在我的项目中实现的图像:
最后它应该是这样的:
帮助将是值得称赞的,并提前感谢。
希望这对您有所帮助。对不起,命名不当。,
<LinearLayout 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" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/dummy"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:visibility="invisible" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/a"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/a"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/a"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.1"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.1"
android:background="@drawable/a"
android:orientation="vertical"
android:visibility="visible" >
</LinearLayout>
<LinearLayout
android:id="@+id/dummy2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:background="@drawable/a"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
<LinearLayout
android:id="@+id/dummy3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/a"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/dummy1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:visibility="invisible" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/a"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/a"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/a"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="50dp"
android:layout_weight="1"
android:orientation="horizontal"
android:visibility="visible" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.8"
android:background="@drawable/c"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/c"
android:orientation="vertical"
android:visibility="visible" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.8"
android:background="@drawable/c"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.8"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/a"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
<LinearLayout
android:id="@+id/LinearLayout04"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/c"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
<LinearLayout
android:id="@+id/LinearLayout02"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/c"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/LinearLayout03"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:visibility="invisible" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/c"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/c"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/c"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:visibility="visible" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2.5"
android:background="@drawable/c"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/c"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2.5"
android:background="@drawable/c"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.05"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/a"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
<LinearLayout
android:id="@+id/LinearLayou"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:background="@drawable/c"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
<LinearLayout
android:id="@+id/LinearL"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:background="@drawable/d"
android:orientation="vertical"
android:visibility="visible" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/Linea"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:visibility="visible" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/c"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/d"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/c"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
您可以使用 RelativeLayout
和 margins/padding
,因为您需要将 images
相加。在这里我用你自己的图片给你一个例子:
(请注意,我手动添加了 width/height
,并不关心 naming
,因为它只是为了测试目的,为您提供有关如何实现它的线索。因此,如果你和 imageViews
的 height/width
一起玩,你也必须和他们的 margins/padding
一起玩)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent">
<ImageView
android:layout_marginLeft="85dp"
android:layout_width="170dp"
android:layout_height="170dp"
android:src="@drawable/tt"
/>
<ImageView
android:layout_marginTop="70dp"
android:layout_width="170dp"
android:layout_height="170dp"
android:src="@drawable/ll"/>
<ImageView
android:layout_marginTop="100dp"
android:layout_marginLeft="90dp"
android:layout_width="170dp"
android:layout_height="170dp"
android:src="@drawable/rr"/>
<TextView
android:gravity="center"
android:layout_marginTop="130dp"
android:layout_marginLeft="100dp"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="This is just a text"/>
</RelativeLayout>
其中:
tt
是上面的曲线rr
是右边的曲线ll
是左边的曲线
结果如下: