CircularImageView show only a half ImageView - android

In my Android app with kotlin, I want to display a user image in the middle AppBar.
The following code is For circular Image :
<com.mikhaellopez.circularimageview.CircularImageView
android:id="#+id/userImage"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="133dp"
android:layout_marginTop="135dp"
android:layout_marginEnd="134dp"
android:layout_marginBottom="14dp"
android:src="#drawable/userprofil"
app:civ_border="true"
app:civ_border_width="2dp"
app:civ_shadow="true"
app:civ_shadow_radius="0"
app:layout_anchor="#id/app_bar_layout"
app:layout_anchorGravity="bottom|center"
app:layout_constraintBottom_toTopOf="#+id/textViewUserName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/app_bar_layout" />
I want a result like this :
But, I get the following result :
What should I change to get the result

The app bar by default has an elevation of 8 dp. So if you are adding any views overlapping with them without adding elevation then they will stay hidden behind the app bar. You need to add elevation more then 8dp on your imageview like below
<com.mikhaellopez.circularimageview.CircularImageView
android:id="#+id/userImage"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="133dp"
android:layout_marginTop="135dp"
android:layout_marginEnd="134dp"
android:layout_marginBottom="14dp"
android:src="#drawable/userprofil"
android:elevation="10dp" // Add this line
app:civ_border="true"
app:civ_border_width="2dp"
app:civ_shadow="true"
app:civ_shadow_radius="0"
app:layout_anchor="#id/app_bar_layout"
app:layout_anchorGravity="bottom|center"
app:layout_constraintBottom_toTopOf="#+id/textViewUserName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/app_bar_layout" />

Just put "translationZ" property in your imageview. so image view comes in front

Related

Circularimage library display square image

I'm Using circulcar image view libary available on github. I also add it to build.gradle and sync it. but i am still not getting circular image. if I add SRC insted of background, still not getting result. where i am wrong?
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/imageView"
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#drawable/splash_screen"
app:civ_border_width="10dp"
app:civ_border_color="#FF000000"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView" />
remove this line : android:background="#drawable/splash_screen"
and Add this line : android:src="#drawable/splash_screen"
Just change the background line. It will show the circular image.
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/imageView"
android:layout_width="200dp"
android:src="#drawable/splash_screen"
android:layout_height="200dp"
app:civ_border_width="10dp"
app:civ_border_color="#FF000000"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView" />
Image was displayed to the background that's why it was showing the square.

ImageView doesn't center on ConstraintLayout

I can't move the image more to the left side no matter what I'm doing. It should be nicely centered but it's not...
image
<ImageView
android:id="#+id/grid"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/back3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/turn"
app:srcCompat="#drawable/back3"
android:layout_gravity="center"/>
Any ideas?
If the parent view is wider than the image, you need to add this to ImageView:
android:scaleType="fitCenter"
or some other appropriate value for the attribute.
When you chain your view to two points using start/end constraints, it stays in the center of those constraints by default. But have the ability to shift it's position toward end or start the layout attribute responsible for this is layout_constraintHorizontal_bias
As #Robert mentioned, you can remove that attribute or set it to 0.5
<ImageView
android:id="#+id/grid"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/back3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/turn"
app:srcCompat="#drawable/back3"
android:layout_gravity="center"/>
Also I suggest you to use AppCompatImageView instead

How to use Android ConstraintLayout component to display any image within a square

I have a player screen where I want to display the artwork provided by an audio file as a square. Most files provide a square artwork, but some will provide a rectangle one.
In that case, I want to use the full height of the image and 'zoom in' losing some information on the right and the left but being able to show it in a square.
Right now I failed to do so.
Also, I would like it to work as well if a vertical rectangle is provided
I'm new to Constraintlayout and try the following but that doesn't work
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:gravity="center"
android:filter="true"
android:padding="20dp"
android:elevation="1dp"
android:scaleType="centerCrop" />
</androidx.constraintlayout.widget.ConstraintLayout>
Any idea on how to achive this?
You can replace android:scaleType="centerCrop" with android:scaleType="fitXY" to change the image default form and ration
From the documentation:
Scale the image using Matrix.ScaleToFit#FILL
<ImageView
android:id="#+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="0dp"
android:src="#drawable/image"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:gravity="center"
android:filter="true"
android:elevation="1dp"
android:scaleType="fitXY" />
I am adding the android studio preview so you can see how it looks:

Padding not working in my Button

In my Button I have this XML:
<Button
android:id="#+id/btnFiltrarResultados"
android:layout_width="18dp"
android:layout_height="17dp"
android:layout_above="#+id/searchView"
android:layout_alignParentEnd="true"
android:layout_marginBottom="-37dp"
android:layout_marginEnd="29dp"
android:background="#drawable/filtrar_explorar"
android:cropToPadding="true"
android:padding="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/txtExploreTitulo"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.01999998" />
But I can't seem to be able to add padding to it. I've tried using cropToPadding or using android:src but nothing seems to help...
You have
android:layout_width="18dp"
android:layout_height="17dp"
and expect padding 20dp
Well it's not a way to add image in button, as you did in your xml fileandroid:background="#drawable/filtrar_explorar". because by default background image try to scale as much as possible and ignore padding.So the good practice is use ImageButton with android:src="#drawable/use_your_image" and add android:scaletype="fitCenter"
<ImageButton
android:layout_width="150dp"
android:layout_height="150dp"
android:src="#drawable/use_your_image"
android:scaleType="fitCenter"
android:padding="10dp"
/>

ImageView Padding attribute not displaying Properly in JellyBean

I have same xml code but when I am running it in Lolipop the padding attribute is working fine but in JellyBean its not working also In my ImageView I am using an oval from drawable that is set with background attribute and transparent wifi image that has set by src attribute
<ImageView
android:id="#+id/imageView"
android:layout_width="42dp"
android:layout_height="42dp"
android:padding="8dp"
android:background="#drawable/icon_circle_primary"
android:src="#drawable/ic_info_black_48dp" />
Here the screenshot from both version
Try putting the ImageView inside of a FrameLayout and put the android:padding="8dp" and the android:background="#drawable/icon_circle_primary" attributes to the FrameLayout.
Something like:
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="50"
android:background="#drawable/icon_circle_primary"
android:padding="8dp">
<ImageView
android:id="#+id/imageView"
android:layout_width="42dp"
android:layout_height="42dp"
android:src="#drawable/ic_info_black_48dp" />
</FrameLayout>
Just in case this will help someone, I had a problem where the ImageView padding was not working for me where I also had android:scaleType="centerCrop" set.
Adding android:cropToPadding="true" did it for me.

Categories

Resources