-1

I have a certain square space for my LinearLayout. Within this LinearLayout i have a RelativeLayout with height and width 100dp. This RelativeLayout has a circular drawable shape. I want to set the height and width of RelativeLayout to be 60% of total space available for its parent LinearLayout. Is there a way to do this?

This is the layout which i am designing enter image description here

This is my xml code snippet of one circular view

 <RelativeLayout
            android:id="@+id/rl_hatchback"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"

            >
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_centerInParent="true"
                android:orientation="vertical">

            <RelativeLayout
                android:id="@+id/rl_hatchback_circle"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:background="@drawable/circle_red"

                >
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/ic_hatchback"
                    android:layout_centerInParent="true"
                    />
            </RelativeLayout>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/rl_hatchback_circle"
                    android:text="Hatchback"
                    style="@style/CircularTitle"
                    />
            </LinearLayout>
Burhanuddin Rashid
  • 5,260
  • 6
  • 34
  • 51
hasan_shaikh
  • 1,434
  • 1
  • 15
  • 38
  • If you want set in percentage you can use new Constraint layout and set guidelines according to your percentage – Burhanuddin Rashid Oct 22 '16 at 08:42
  • 1. there are many answers for the thing that you want to achieve, so what exactly is the puspose of having that 60% height. 2. your layout is very badly written that can effect your apps performance. 3. once you reply for point#1, i can further help with #1 & #2 – Mohammed Atif Oct 22 '16 at 08:55
  • can you please suggest me the best way to represent this layout – hasan_shaikh Oct 22 '16 at 09:45
  • I have created 6 parts within the space available using weights. I want to have that circular layout at the center in each block with the text at its bottom. – hasan_shaikh Oct 22 '16 at 09:50

1 Answers1

0

You can use PercentRelativeLayout or ConstraintLayout to reduce number of nested views. For Reference:

PercentRelativeLayout: https://developer.android.com/reference/android/support/percent/PercentRelativeLayout.html

ConstraintLayout: https://developer.android.com/training/constraint-layout/index.html

Barış Söbe
  • 470
  • 4
  • 7