So I'm working on making a design for my app and I need to put a imagebutton directly below an imageview. But since my imageview has a border around it with a drop shadow I need to hide (shift up) maybe 10 pixels of my imagebutton behind my imageview. Here is a quick drawing of what I want.
I hope that makes sense. I've been messing around with all kinds of different arrangements but I cant get what I want. Any help would be greatly appreciated.
First of all use a RelativeLayout. Add first the ImageButton and then the ImageView, in this way the ImageView will be on top of your ImageButton. Then you should set on your ImageButton the following :
<ImageButton
....
android:layout_below="#id/ImageViewId"
android:layout_marginTop="-10px" />
Use relative layout as said. Refer
http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html
for more positions and easy design.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/Imageview"
android:layout_marginTop="-16dp" />
<ImageView
android:id="#+id/Imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="46dp"
android:adjustViewBounds="true"
android:contentDescription="#string/description_logo"
android:src="#drawable/imagename" />
</RelativeLayout>
Related
I have the following code snippet:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/collected_item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/card_text_color"
android:textSize="#dimen/card_headline_textsize"
android:layout_marginBottom="#dimen/card_headline_marginBottom"
android:text="Foo" />
<ImageView
android:id="#+id/collected_item_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxHeight="140dp"
android:background="#android:color/holo_red_dark"
android:adjustViewBounds="true"
android:layout_below="#id/collected_item_title"
android:layout_marginEnd="8dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/collected_item_image"
android:layout_below="#id/collected_item_title"
android:text="Foo"
android:textColor="#color/card_text_color" />
</RelativeLayout>
I like to have the ImageView on the left and the second TextView either on the right of this image or unter the image, dependent on the size of the image.
The image should grow, until it reaches a maximum height of 140dp.
How can I automatically wrap the text if the image get's too width?
Unfortunately I have no idea at the moment how to do it.
Yes I can do it programmatically, but I like to reach the goal only with xml.
The wrapping RelativeLayout doesn't have to be a RelativeLayout, if this behaviour is possible with an other layout.
It sounds like you need a FlowLayout. Android does not provide one out-of-the-box, but check out this answer. How can I do something like a FlowLayout in Android?
Thanks to the answer of chessdork, I found the flexbox layout of google.
It gets provided by the following git repository.
https://github.com/google/flexbox-layout
I have 2 layouts in my xml, a CircularImageView and a ImageView, and the ImageView must appear on top of the CircularImageView.
I've tried:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragment_kids_register_ll_kid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/md_white_1000"
android:orientation="horizontal">
<RelativeLayout
android:padding="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.mikhaellopez.circularimageview.CircularImageView
android:id="#+id/fragment_kids_row_img_kids"
android:layout_width="70dp"
android:layout_height="70dp"
android:src="#drawable/ic_boy"
/>
<ImageView
android:id="#+id/fragment_kids_row_iv_crown"
android:layout_toRightOf="#+id/fragment_kids_row_img_kids"
android:layout_marginLeft="-26dp"
android:layout_marginTop="-22dp"
android:layout_width="48dp"
android:layout_height="48dp"
android:src="#drawable/ic_crown"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/fragment_kids_row_tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:textColor="#color/md_black_1000"
android:textSize="24sp" />
<TextView
android:id="#+id/fragment_kids_row_tv_age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="1 ano e 4 meses"
android:textColor="#808080"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
And it is getting cut off:
I need the image to be shown exactly at that position in the picture, but not "cropped", what I am missing here ?
BTW, this component is part of a RecyclerView row.
EDIT ---
I forgot to mention, the image is just a placeholder to show the Avatar, but the image is dinamically populated !
Thanks !
The padding (16dp) that you are applying to the first relativeLayout makes you think that there is more place and that you can move up the imageView. Actually the margin is like a gap, it doesn't extend your layout.
This is the solution I suggest , using a FrameLayout
<FrameLayout
android:layout_width="100dp"
android:layout_height="100dp">
<com.mikhaellopez.circularimageview.CircularImageView
android:id="#+id/fragment_kids_row_img_kids"
android:layout_gravity = "center"
android:layout_width="70dp"
android:layout_height="70dp"
android:src="#drawable/ic_boy"
/>
<ImageView
android:id="#+id/fragment_kids_row_iv_crown"
android:layout_width="48dp"
android:layout_height="48dp"
android:src="#drawable/ic_crown"
android:layout_gravity="right|top" />
</FrameLayout>
EDIT : You don't have to use a frameLayout, you can use a relativeLayout if you want to set different margins. The point here is really to make your containing layout bigger so you can place the imageview easily.
If you want one image to be on top of another, why you use android:layout_toRightOf?
Remove it and second image should cover first one.
Also you can try to remove margins at second image and use centerInParent, centerVertically or centerHorizontally.
Or maybe I didn't got all the problem ) then pls provide more details. Thanks.
Have you tried Using an image editor like Paint/Photoshop and merging the two images? Then you can just display one image in your view.
try using a linear layout with the orientation set to vertical.
I have an image button shape like a 'star' and i what the clickable area to be only the 'star' but instead of that i have a transparent square clickable area around the 'star', can anyone please tell me how to remove the square bcoz the next 'star' it's close and the square overlaps the first 'star'.
thank you so much
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:layout_weight="1"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="190dp"
android:layout_marginBottom="180dp">
<ImageButton
android:id="#+id/star"
android:layout_width="120dp"
android:layout_height="120dp"
android:background="#drawable/star"
/>
Instead of ImageButton you can user ImageView and make in clicable.
Set
android:background=#android:color/transparent
and insert
android:src=#drawable/star
Or just use an ImageView instead, because you can have OnClickListener on both, therefore they could also function as described in your question.
You can use:
android:background="#null"
in the imageButton tag.
I want to put png image over button i tried android:background but the png takes all the button what i want exactly is to use the logo png over button like this
the info logo is my png and "about" comes from the button text
u can use this:
android:drawableTop="#drawable/SomeIcon"
so then you get this:
<Button
android:id="#+id/damage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="about"
android:drawableTop="#android:drawable/ic_menu_info_details"/>
it works for me :)
You can use a FrameLayout. In a FrameLayout, the z-index is defined by the order in which the items are added, for example
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_text" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/my_drawable"
android:scaleType="fitCenter"/>
</FrameLayout>
In this instance, the ImageView would be drawn on top of the Button, along the bottom center of the Button.
You can check this thread
Basically, you can use:
<ImageButton
android:id="#+id/ImageButton01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/album_icon"
android:background="#drawable/round_button" />
As the thread says.
Take a RelativeLayout, place ImageView inside it. Now set onClickListener on RelativeLayout.
By this way you can create more complex buttons.
<RelativeLayout android:id="#+id/your_btn_id"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
</RelativeLayout>
you can use
android:drawableTop
to put drawable at top of Button and use appropriate padding to make it position well.
<Buttton
android:layout_width="99dp"
android:layout_height="99dp"
android:background = "#drawable/bg" />
bg is your custom image.
I've got an ImageView centered inside a RelativeLayout using android:layout_centerHorizontal="true" and android:layout_centerVertical="true".
Can I animate (move) it to let's say the bottom right corner, using XML and/or code? I'd like to specify the duration of the animation as well as possibly the curve.
Before:
<ImageView android:id="#+id/imageview01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/imagefile" />
After:
<ImageView
android:id="#+id/imageview01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="#drawable/imagefile" />
check Android Translate Animation
Piggybacking on Mosh, this looks to be a helpful earlier answer:
Full example of how to programmatically do RotateAnimations?