Place Circular ImageViews on another in a row - android

What is the best approach to create a symmetry of circular images over each other same like shown below.
Any library or any custom widget? Or just we can do this with ConstraintLayout?

with this library you can make a circle view
<com.github.florent37.shapeofview.shapes.CircleView
android:layout_width="150dp"
android:layout_height="150dp"
android:elevation="4dp"
app:shape_circle_borderColor="#android:color/black"
app:shape_circle_borderWidth="2dp">
<!-- YOUR CONTENT -->
</com.github.florent37.shapeofview.shapes.CircleView>
Secend Step
add all circle views in a linear Layout and set negative margin to below viwes for Example i Use image view
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:srcCompat="#tools:sample/avatars" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-30dp"
tools:srcCompat="#tools:sample/avatars" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-30dp"
tools:srcCompat="#tools:sample/avatars" />
</LinearLayout>

Related

Parent view is overlapped by child view

I am developing an Android application in which I would like to display the GridView using RecyclerView.
I could able to create separate layout for an item and display it in GridView dynamically.But I face an issue in showing tick mark on top right of each item.
The tick mark is hidden by CardView
Here is my item_grid.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="110dp"
android:layout_height="110dp">
<android.support.v7.widget.CardView
android:id="#+id/cardView2"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="10dp"
android:elevation="#dimen/activity_horizontal_margin">
<ImageView
android:id="#+id/image_hobby_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:src="#drawable/cycling" />
<TextView
android:id="#+id/text_hobby_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/colorAccent"
android:gravity="center"
android:padding="3dp"
android:paddingBottom="15dp"
android:paddingTop="15dp"
android:text="CYCLING"
android:textColor="#android:color/white"
android:textSize="12sp"
android:textStyle="bold" />
</android.support.v7.widget.CardView>
<ImageView
android:id="#+id/image_hobby_selected_icon"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="top|right"
android:adjustViewBounds="true"
android:src="#drawable/all_checked_round" />
</FrameLayout>
I have tried bringToFront() method but it is not working.
viewHolder.checkMark.bringToFront();
((View) viewHolder.checkMark.getParent()).invalidate();
(viewHolder.checkMark.getParent()).requestLayout();
Please help me find the solution.
Please use elevation.
If your card view has elevation as 10dp, then set elevation in imageView as 11dp.
<ImageView
android:id="#+id/image_hobby_selected_icon"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="top|right"
android:adjustViewBounds="true"
android:src="#drawable/ic_camera"
android:elevation="13dp"
/>

Imageviews positioning over Imageviews

I have three ImageViews positioned on top of one each other. But when the screen resolution or parent ImageView size changes, the child ImageViews position retain their old position. These old positions are wrong for the new parent ImageView size. How can I calculate the new positions? Or is there another way to solve this problem?
Every image on top of the dummy is an ImageView in this screenshot of my work:
I use absolute layout and it's work for me. Here is example code;
<AbsoluteLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="#+id/save"
android:nestedScrollingEnabled="true"
android:background="#eeeeee">
<ImageView
android:layout_width="wrap_content"
android:layout_height="400dp"
android:id="#+id/imageView"
android:src="#drawable/dummy2"
android:layout_alignParentLeft="true"
android:layout_marginLeft="30dp"
android:layout_alignParentTop="true"
android:layout_marginTop="0dp"
android:scaleType="fitStart"
android:layout_y="20dp"
android:layout_x="30dp" />
<ImageView
android:layout_width="166dp"
android:layout_height="200dp"
android:id="#+id/k_altkiy_v"
android:layout_x="-2dp"
android:layout_y="170dp" />
<ImageView
android:layout_width="120dp"
android:layout_height="200dp"
android:id="#+id/k_ustkiy_v"
android:layout_marginTop="85dp"
android:layout_alignParentTop="true"
android:adjustViewBounds="false"
android:scaleType="fitStart"
android:layout_x="28dp"
android:layout_y="66dp" />
<ImageView
android:layout_width="128dp"
android:layout_height="200dp"
android:id="#+id/k_cek_v"
android:layout_x="16dp"
android:layout_y="50dp" />
</AbsoluteLayout>

Set Space between imageview and two buttons in android

I have layout in which i have one ImageView and two Buttons.Now i want to set space between imageView and 2 Buttons.
XML
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/companyLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".1"
android:layout_gravity="left"
android:adjustViewBounds="true"
android:background="#mipmap/ic_launcher" />
<Button
android:id="#+id/clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:gravity="right|center"
android:text="Clear" />
<Button
android:id="#+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:gravity="right|center"
android:text="Apply" />
</LinearLayout>
I tried by setting weight but it didn't worked for me.Please help me in this
You can use paddings, margins or instances of Space class in your layout to add some space between views. You didn't specify the desired result, so choose something that suits your needs.
BTW, Space is the better alternative for this task compared to View class because it was designed to be light-weight spacing widget and it doesn't make some computations that ordinary View does.
try to add android:layout_margin="20dp" :
<ImageView
android:id="#+id/companyLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".1"
android:layout_margin="20dp"
android:layout_gravity="left"
android:adjustViewBounds="true"
android:background="#mipmap/ic_launcher" />
you can add margin only for one side like that:
android:layout_marginTop="20dp" /
android:layout_marginLeft="20dp"/
android:layout_marginBottom="20dp" /
android:layout_marginRight="20dp"
look here for more, ViewGroup.MarginLayoutParams
<View
android:clickable="true"
android:layout_gravity="center"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
Write this view in between ImgaeViews and Button.
It will work

Overlap views in horizontal LinearLayout

I need to design a layout with five ImageViews in horizontal orientation.
I can reach my idea with a basic LinearLayout, but I want a design pattern like the following image:
Note: All ImageViews are in oval design.
Any ideas?
you can overlap items in a LinearLayout using negative margins, but they won't stack in that order.
you could use a RelativeLayout instead. you'd lay out the items from outside to inside to achieve the desired stacking order.
here's an example with a fixed width:
<RelativeLayout android:layout_width="150dp" android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentLeft="true" android:layout_centerVertical="true" />
<ImageView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentRight="true" android:layout_centerVertical="true" />
<ImageView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentLeft="true" android:layout_centerVertical="true"
android:layout_marginLeft="25dp" />
<ImageView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentRight="true" android:layout_centerVertical="true"
android:layout_marginRight="25dp" />
<ImageView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" android:layout_centerVertical="true" />
</RelativeLayout>
if you don't have a fixed-width container, you'll have to calculate the margins in code with this approach.
of course, if you don't have a fixed width, you'll need code of some sort anyway as there's nothing built into android that's really meant for this sort of thing.
You can use a RelativeLayout for this task. Here's an example:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/img1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="-18dp" />
<ImageView
android:id="#+id/img2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/img1"
android:layout_marginRight="-18dp" />
<ImageView
android:id="#+id/img5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/img4"
android:layout_marginRight="-18dp"/>
<ImageView
android:id="#+id/img4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/img3"
android:layout_marginRight="-18dp" />
<ImageView
android:id="#+id/img3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/img2"
android:layout_marginRight="-18dp" />
</RelativeLayout>
Note that here, the last ImageView is the one that will be on top of all others.
You are looking for developing a Carousel kind of widgets. You can refer any Carousel implementation in android. Many are available, you can refer one here
https://code.google.com/p/carousel-layout-android/

How to make frames to ImageButtons?

I'm developing an android app that contains two image buttons, these image buttons seem to be frameless or don't have bounds around them , look at the following figures:
instead, i want to make the buttons look like if they have bounds on their edges, like the following figure:
and that's my XML code:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:orientation="horizontal" >
<ImageButton
android:contentDescription="#string/minus"
android:id="#+id/mines"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:adjustViewBounds="true"
android:padding="10dp"
android:background="#21417D"
android:scaleType="centerInside"
android:src="#drawable/ac_button_minus" />
<ImageButton
android:contentDescription="#string/plus"
android:id="#+id/plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:adjustViewBounds="true"
android:layout_marginRight="15dp"
android:padding="10dp"
android:background="#21417D"
android:scaleType="centerInside"
android:src="#drawable/ac_button_plus" />
</LinearLayout>
If you just want the spacing between the buttons use the attribute android:layout_margin in your xml, you can specify individual sides too so e.g.
<ImageButton
...
android:layout_marginLeft="16dp"
...
android:scaleType="centerInside"
android:src="#drawable/ac_button_minus" />

Categories

Resources