简体   繁体   English

我如何在Android XML设计中使用多种形状

[英]How can i use multiple shapes in android xml design

I am very new to android and trying to create a design like this in xml. 我对android非常陌生,并尝试在xml中创建这样的设计。 图片说明在这里

I was able to create the left most portion of the design which has circle within a circle and a textview. 我能够创建设计的最左侧部分,该部分在一个圆圈内有一个圆圈,并具有一个textview。 在此处输入图片说明

Following are the files i have created for the above. 以下是我为以上创建的文件。

/drawable/design_circle.xml /drawable/design_circle.xml

<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item

    android:top="6dp"
    android:right="6dp"
    android:bottom="6dp"
    android:left="6dp">
    <shape
        android:shape="oval">
        <stroke
            android:width="1dp"
            android:color="#78d9ff"/>
    </shape>
</item>
<item>
    <shape
        android:shape="oval">
        <stroke android:width="4dp"
            android:color="#78d9ff"/>
    </shape>
</item>

/layout/view.xml /layout/view.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 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">
<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="150dp"
    android:layout_gravity="center"
    >
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">
        <TextView
            android:id="@+id/ec_txtDate"
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:background="@drawable/design_circle"
            android:text="09"
            android:textAlignment="center"
            android:gravity="center_vertical"
            android:textStyle="bold"
            android:textSize="50dp"/>
    </RelativeLayout>
</android.support.v7.widget.CardView>

But i am not able to create * OCTOBER * section of the design which has to adjacent to the circle. 但是我无法创建必须与圆圈相邻的设计的*十月*部分。 Thank you in advance. 先感谢您。

If you don't want to give clicks on each of that sub sections use the image instead.You completed the left side, when looking i think you will be expecting click on the circle so make the image into two give an image view right of the shape you created 如果您不想在每个子部分上单击,请使用image.You来完成左侧,当我看时,我认为您会期望单击圆圈,因此将图像分成两部分,即可得到右侧的图像视图您创建的形状

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="150dp"
    android:layout_gravity="center"
    >
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center"//give this to align the objects in this view center alignment
        android:orientation="vertical"//remove this because it is not relevant for a relative layout but relevant for linearlayout>
        <TextView
            android:id="@+id/ec_txtDate"
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:background="@drawable/design_circle"
            android:text="09"
            android:textAlignment="center"
            android:gravity="center_vertical"
            android:textStyle="bold"
            android:textSize="50dp"/>
        <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_toRightOf="@+id/"ec_txtDate
                android:src="@drawable/your_image.png" />
    </RelativeLayout>
</android.support.v7.widget.CardView>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM