I'm having trouble positioning a button on an image view.
I want to put a button on top of the image view, so that the button is "on" the image.
So far, I've put done it in a way, such as
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
and the button is added programatically when the app starts(at "onCreate"), so the button is shown on top of the image.
It works fine, but the problem is when I zoom/drag the image.
I want the button to move/zoom with the image, but with what I've got above, the button stays at a fixed position on a screen and only the image is being zoomed/dragged.
Is there a way I can do this?
Thanks in advance.
Related
I want to make a view( a button actually) which is inside a scrollview , but when the user scolls down and the button is going up, it moves up only till it reaches the top of the visible screen and then stays there like a fixed header until the user scrolls up again and then it returns to its original position.
I have given the screens for understanding ;
At Start
Then
Change you parent viewgroup to RelativeLayout and then make a Button and ScrollBar as a direct child of this RelatieveLayout.
You can simply achive this by
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
------put your code here-----/>
<Button
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</FrameLayout>
I want to do the imageView layout with the button to edit photo inside.
I think to put image as imageView background but i donĀ“t know how to do the semicircle transparency and set the icon.
Any ideas?
UPDATE
Now i have this.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="150dp"
android:layout_height="150dp"
android:background="#color/blue_bar">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/image"
android:scaleType="centerCrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#color/black"/>
<ImageButton
android:layout_alignStart="#+id/image"
android:layout_alignEnd="#+id/image"
android:src="#drawable/ic_edit_photo"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#B3ffffff"/>
</RelativeLayout>
Can i do the imageButtons background as a semicircular shape?
For that you have to make a CompoundView.
1) I would make a RelativeLayout with the imageview width and height set to match_parent, then a button with alignBottom set to true.
2) Then keep using your button normally in your Activity.
3) You can go fancier and use a CompoundView extending ViewGroup and putting the functionality of the button.
Here is a tutorial for it:
http://www.vogella.com/tutorials/AndroidCustomViews/article.html
I hope it helps.
Before I implemented a linear layout with button and webview, my standalone webview worked fine. I added the following and now only the button shows up:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<ImageButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/back_nav"
/>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
I just want a button that spans the top, with a webview underneath it that fills the rest of the view.
What am I doing wrong?
Your orientation is set to horizontal, and the button is set to "fill_parent", so that means the webview will come to the right of the button, which fills the entire screen, making the webview appear off the screen.
To fix this, set orientation of your LinearLayout to "vertical".
In Android UI design using XML, how is it possible to put an ImageButton to align exactly with the background of the activity xml file.
Suppose, I have two images, one acts as the background image for the activity, and the second one acts as the image button source.
This is the background image.
http://i.stack.imgur.com/e1Ow5.png
This is the button image. http://i.stack.imgur.com/m0tUU.png
I will set the first image as background to the activity. My question is how will I properly place and align the second image,that is the button to be exactly inside the "central rectangle" of the background. The "central rectangle" is the place holder, and it can be anywhere in the screen.
Not: I tried using relative layout, but, couldn't really place the button depending on the background.
Edit:-
Actually the rectangle and the rounded-rectangle at the center of the background is just a place-holder. It can be anything, even nothing. Or it can be anywhere. It might not be at the center. Consider the whole image, I need to put the button image where the place-holder is. That is my intention. Say for example , consider a radio application, where there is a turning button acting as volume rocker. Everything else in the image is the background, and the volume rocker might be a different image.
The answer is its impossible the way your are trying to do it.
What you want to do is cut the background up further so the button is centered.
So using your images as an example, here is how the view hierarchy would look
->FrameLayout1
---->Framelayout2
-------->Button
FrameLayout1 would be the background without the inner square
FrameLayout2 would be the inner square
Button would the button asset and placed centered in FrameLayout 2.
There are other techniques on top of this you will need to make it look pixel perfect, like using 9 patch drawables.
Considering you are trying out in landscape mode( your images seems so)
You can try the following code.
bg : your background
img: your center image
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/img" />
</RelativeLayout>
<?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/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/img_bg" />
</RelativeLayout>
drawable/img_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/bg">
</item>
<item android:drawable="#drawable/fr">
</item>
</layer-list>
or
<?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/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/bg" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/imageView1"
android:src="#drawable/fr" />
</RelativeLayout>
bg.png and fr.png are transparent image with same height and width.
i am develop project with gallery control in android.but,i have some problem in gallery control i am scroll one image to next image shows shadows like starting image not shadow in gallery control and i am scroll to next image to shows shadow for all images in gallery control.i want remove shadow in gallery control.
i am getting output below screen shot:
i
i am scroll to next image output below screen shot:
here's my xml code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/black"
android:id="#+id/lay_linear"
android:orientation="vertical" >
<Gallery
android:id="#+id/gallery"
android:layout_width="fill_parent"
android:layout_height="430dp"
android:layout_weight="2.50" />
</LinearLayout>
i want remove shadows on gallery control.can help me any one greatly appreciated!
Try below code for remove unselected shawdows:
galleryview.setUnselectedAlpha(1);
Welcome!
Use android:cacheColorHint="#00000000"