3

i had tried with circular layout,relative layout,constraint layout to design.i had designed it properly but alignment was changing from device to device.how to solve that problem.

<io.github.francoiscampbell.circlelayout.CircleLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:cl="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    cl:cl_angleOffset="0"
    cl:cl_angle="60"
    cl:cl_direction="clockwise"
    cl:cl_centerView="@+id/centerView">

    <Switch
        android:id="@+id/centerView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="hii all"
        android:textColor="@color/error_color"
        android:textSize="18sp" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"/>

    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <SeekBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</io.github.francoiscampbell.circlelayout.CircleLayout>

how to design shown below

vinay
  • 149
  • 7

1 Answers1

4

You can use ConstraintLayout for circle alignment (using circle constraint,ofcourse), as you need. Check the below example:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.example.developer.widget.CircleImageView
        android:id="@+id/center"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:src="@color/colorPrimary"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


    <com.example.developer.widget.CircleImageView
        android:id="@+id/first"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:src="@color/colorAccent"
        app:layout_constraintCircle="@+id/center"
        app:layout_constraintCircleAngle="90"
        app:layout_constraintCircleRadius="110dp" />

    <TextView
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Book"
        app:layout_constraintLeft_toLeftOf="@+id/first"
        app:layout_constraintTop_toBottomOf="@+id/first" />

    <com.example.developer.widget.CircleImageView
        android:id="@+id/second"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:src="@color/colorAccent"
        app:layout_constraintCircle="@+id/center"
        app:layout_constraintCircleAngle="145"
        app:layout_constraintCircleRadius="110dp" />

    <TextView
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Shop"
        app:layout_constraintLeft_toLeftOf="@+id/second"
        app:layout_constraintTop_toBottomOf="@+id/second" />

    <com.example.developer.widget.CircleImageView
        android:id="@+id/third"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:src="@color/colorAccent"
        app:layout_constraintCircle="@+id/center"
        app:layout_constraintCircleAngle="215"
        app:layout_constraintCircleRadius="110dp" />

    <TextView
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Book"
        app:layout_constraintLeft_toLeftOf="@+id/third"
        app:layout_constraintTop_toBottomOf="@+id/third" />


    <com.example.developer.widget.CircleImageView
        android:id="@+id/fourth"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:src="@color/colorAccent"
        app:layout_constraintCircle="@+id/center"
        app:layout_constraintCircleAngle="270"
        app:layout_constraintCircleRadius="110dp" />

    <TextView
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Book"
        app:layout_constraintLeft_toLeftOf="@+id/fourth"
        app:layout_constraintTop_toBottomOf="@+id/fourth" />


</android.support.constraint.ConstraintLayout>

Output:

Circle Constraint

Yamini Balakrishnan
  • 2,361
  • 16
  • 24
  • I'm also working on a layout similar to this one. In my layout the main circle should stretch the whole layout (with some padding) so I set `layout_constraintDimensionRatio="1:1"`. Do you have any ideas how I can set the radius then properly? Or do I have to work with layout size qualifiers? – Cilenco Mar 05 '18 at 12:38