Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
206 views
in Technique[技术] by (71.8m points)

android - is this the right way to create a custom round corner layout like this?

I want to create a layout like this.layout

The big rectangle will be divided into smaller rectangles (with rounded corners) shown in yellow. I want to place my items like image in the smaller rectangles. I do not know what to search for to get related links. I do not know that is why asking. I think this is a place for experts only.
yellow rectangles are not a problem, but how to create that additional layout inside another layout. Like if I declare a layout inside another layout, it will take the whole space. How to get a border of rounded corners that leaves space at 4 sides.
I was adviced to use shape xml. But I want a layout where I can place child components and not a drawable.

I made a code. I want to know if it is the right way to do?
CODE:

        drawable/round_corner_rectangle.xml:      
        <?xml version ="1.0" encoding ="utf-8"?><!--  Learn More about how to use App Actions: https://developer.android.com/guide/actions/index.html -->
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle">
        
            <corners
                android:bottomRightRadius="10dp"
                android:topRightRadius="10dp"
                android:topLeftRadius="10dp"
                android:bottomLeftRadius="10dp"
                 />
        
            <gradient
                android:angle="45"
        
                android:endColor="#0a91ee"
                android:gradientRadius="41dp"
                android:startColor="#0f29eeaa"
                android:type="linear" />
            <!--android:centerX="float"
            android:centerY="float"-->
        
            <!--If your shape requires only one solid color-->
            <!--<solid
                android:color="#FFFFFF" />-->
        
            <size
                android:width="482dp"
                android:height="200dp" />
        
            <!--Use android:dashWidth="2dp" and android:dashGap="2dp"
            to add dashes to your stroke-->
            <stroke
                android:width="2dp"
                android:color="#FFFFFF" />
        
            <!--If you want to add padding-->
            <!-- <padding
                 android:left="10dp"
                 android:top="20dp"
                 android:right="40dp"
                 android:bottom="8dp" />-->
        
        </shape>
    
    drawable/drawii.xml:      
    
        <?xml version ="1.0" encoding ="utf-8"?><!--  Learn More about how to use App Actions: https://developer.android.com/guide/actions/index.html -->
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle">
        
            <corners
                android:bottomRightRadius="10dp"
                android:radius="40dp" />
        
            <gradient
                android:angle="45"
        
                android:endColor="#01f1fa"
                android:gradientRadius="41dp"
                android:startColor="#0189ff"
                android:type="linear" />
            <!--android:centerX="float"
            android:centerY="float"-->
        
            <!--If your shape requires only one solid color-->
            <!--<solid
                android:color="#FFFFFF" />-->
        
            <size
                android:width="82dp"
                android:height="82dp" />
        
            <!--Use android:dashWidth="2dp" and android:dashGap="2dp"
            to add dashes to your stroke-->
            <stroke
                android:width="2dp"
                android:color="#FFFFFF" />
        
            <!--If you want to add padding-->
            <!-- <padding
                 android:left="10dp"
                 android:top="20dp"
                 android:right="40dp"
                 android:bottom="8dp" />-->
        
        </shape>
          
    layout/activity_main.xml:      
    <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent" android:orientation="vertical"
        android:gravity="fill_vertical" android:layout_margin="10dp"

        >
        <!--android:padding="10dp"-->
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World!"
             />
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent" android:orientation="horizontal"
            android:gravity="fill_horizontal"
            android:background="@drawable/round_corner_rectangle"
            android:layout_margin="0.5dp"
            >
            <!--android:layout_margin="20dp"-->
            <ImageButton
                android:id="@+id/imageButtonGenerateBulk"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="25dp"

                android:layout_gravity="center_vertical"
                android:ellipsize="end"
                android:scrollHorizontally="true"
                android:singleLine="true"
                android:text="Generate Qr Code"
                android:textStyle="bold"
                android:layout_alignEnd="@+id/tv_question"
                android:layout_alignRight="@+id/tv_question"
                android:background="#00ffffff"
                android:src="@drawable/drawii"
                android:layout_weight="1"/>
            <ImageButton
                android:id="@+id/imageButtonGenerateBulk2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="25dp"

                android:layout_gravity="center_vertical"
                android:ellipsize="end"
                android:scrollHorizontally="true"
                android:singleLine="true"
                android:text="Generate Qr Code"
                android:textStyle="bold"
                android:layout_alignEnd="@+id/tv_question"
                android:layout_alignRight="@+id/tv_question"
                android:background="#00ffffff"
                android:src="@drawable/drawii"
                android:layout_weight="1"/>
        </LinearLayout>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent" android:orientation="horizontal"
            android:gravity="fill_horizontal"
            android:background="@drawable/round_corner_rectangle"
            android:layout_margin="0.5dp"
            >
            <!--android:layout_margin="20dp"-->
            <ImageButton
                android:id="@+id/imageButtonGenerateBulk3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="25dp"

                android:layout_gravity="center_vertical"
                android:ellipsize="end"
                android:scrollHorizontally="true"
                android:singleLine="true"
                android:text="Generate Qr Code"
                android:textStyle="bold"
                android:layout_alignEnd="@+id/tv_question"
                android:layout_alignRight="@+id/tv_question"
                android:background="#00ffffff"
                android:src="@drawable/drawii"
                android:layout_weight="1"/>
            <ImageButton
                android:id="@+id/imageButtonGenerateBulk4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="25dp"

                android:layout_gravity="center_vertical"
                android:ellipsize="end"
                android:scrollHorizontally="true"
                android:singleLine="true"
                android:text="Generate Qr Code"
                android:textStyle="bold"
                android:layout_alignEnd="@+id/tv_question"
                android:layout_alignRight="@+id/tv_question"
                android:background="#00ffffff"
                android:src="@drawable/drawii"
                android:layout_weight="1"/>
        </LinearLayout>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent" android:orientation="horizontal"
            android:gravity="fill_horizontal"
            android:background="@drawable/round_corner_rectangle"
            android:layout_margin="0.5dp"
            >
            <!--android:layout_margin="20dp"-->
            <ImageButton
                android:id="@+id/imageButtonGenerateBulk5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="25dp"

                android:layout_gravity="center_vertical"
                android:ellipsize="end"
                android:scrollHorizontally="true"
                android:singleLine="true"
                android:text="Generate Qr Code"
                android:textStyle="bold"
                android:layout_alignEnd="@+id/tv_question"
                android:layout_alignRight="@+id/tv_question"
                android:b

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...