I'm using the following xml code for my camera layout:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/preview"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/buttonClick"
android:text="Click" android:layout_gravity="right|bottom" />
</FrameLayout>
When the user clicks the screen it will capture the image.
Now what I want to do is to have another button in the same view to launch my image viewer, how to do this? I want something like this (image viewer button on the lower right corner):
Many thanks for any help! :)
You can create a button and set android:layout_gravity="right|bottom"
You need to create a button with a custom background. On the click method you need to implement a new intent like this.
startActivity(new Intent("[here is your imageViewer's package name]");
Hope it helps.
Related
What I need in general: replace(hide) one view with another by a button click
Let's go deep in details:
I use ViewPager, which consists of 100 images.
Layout of ViewPager
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#ffffff" >
</android.support.v4.view.ViewPager>
<ImageButton
android:id="#+id/imagePlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageRight"
android:layout_alignTop="#+id/imageList"
android:src="#drawable/list" />
</RelativeLayout>
Layout of Image
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="1dip"
android:background="#ffffff">
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>
</RelativeLayout>
It works - no problems. But I need to add button to the viewpager and after tapping image in the viewpager should be changed to the gif. It looks like gifs preview and after onclick play - gif starts to play.
Custom layout for gifs:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageList"
android:layout_marginRight="28dp"
android:layout_toLeftOf="#+id/imageRight" >
<com.basv.gifmoviewview.widget.GifMovieView
android:id="#+id/gif1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
How it should be resolved? It's pretty simple for me to open another activity after tapping to the button, but the issue is to play gif in the same Fragment
Any ideas?
I'd simply add your com.basv.gifmoviewview.widget.GifMovieView somewhere to your root RelativeLayout (perhaps you may need to wrap both ViewPager and GifMovieView in additional FrameLayout) and simply show/hide it when needed using ordinary setVisibility().
EDIT
I suppose it's not the best solution for phones' memory usage
I quickly looked into the sources and there's no much code really. So if you bother memory usage you can always dynamically create widget prior showing it (and destroy once hidden) or, as I cannot see the method to "unload" a GIF, you can always use "1x1 px" empty Gif to ensure last one you just stopped showing is no longer occupying precious memory if not needed.
Here is an idea. Make that layout with both view pager and gif but the gif visibility set to invisible so that initially its there but not visible. But when someone click the button you should put that gif to life in code by setting it to visible while also changing view pager to invisible or gone in case you dont even want its initial boundary being present!!
I am working on application in which gallery require as bellow image :
I searched over internet but it gives result similar to Image Gallery. But I want to create the gallery which will move in circular fashion, means it just bend the first and last member of gallery. Is it possible? or Is the horizontal ScrollView better approach to do this?
Any better approach will be appreciated.. Thanks in advance.
I have found a solution and it achieved using Custom Gallery. I used following layout file for that
main.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linear_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/gal_bg"
android:orientation="vertical" >
<Gallery
android:id="#+id/horizontallistview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp" />
<!-- android:background="#drawable/gal_overlay" -->
<ImageView
android:layout_width="fill_parent"
android:layout_height="120dp"
android:background="#drawable/gal_overlay" />
</FrameLayout>
And it uses the some images as background to FrameLayout and ImageView. You will find the complete source code of project on GitHub.
Happy Coding..
i am designing an application which have diff types of functionalies through buttons/image buttons. At final the list might increase. i want to put one custom home button which always keeps on screen when i am in diff activities.
or either if you have any idea about how this Home button is coded to this layout
below screen. please help.
Have you considered the Action Bar which is exactly designed for this purpose?
http://developer.android.com/guide/topics/ui/actionbar.html
While the home button at the bottom can be easily achieved using an image view/button,Using an action Bar is the recommended option.Not only can you link with the home activity but also any other activity of your choice.Refer this to gain a deeper insight.
http://developer.android.com/guide/topics/ui/actionbar.html
http://developer.android.com/reference/android/app/ActionBar.html
You can either place a button/image button/image anything in xml layout and set on click listener on that component. You can also use option menu and give multiple option on all the screens of your application.
Make a layout with a ScrollView on top, and your image-button below the scrollview.
Example:
<!-- language: lang-xml -->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Your Content Here"
/>
</ScrollView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
/>
</LinearLayout>
</LinearLayout>
It looks like this:
As you can see from the question I need to put some button on mapView, where the app will by presing the button by user, refresh the mapView with current location.
I know how to put the button above, under, but how to put on map???
If anyone has some sample code, or some guidance help is appreciated...
You'll want to use a RelativeLayout and lay the button over top of the MapView. Just make sure not to place it over the Google logo. Here's a sample XML:
<?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">
<com.google.android.maps.MapView android:id="#+id/google_maps"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="#string/maps_key"/>
<Button android:id="#+id/googlemaps_select_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Select"/>
</RelativeLayout>
Hi man search for overlay item is what you need :D here google link
http://developer.android.com/resources/tutorials/views/hello-mapview.html
and good sample :D
https://github.com/jgilfelt/android-mapviewballoons
I want to put button above image view.
How can i do this?
(Please, don't offer to set Background, cause i need ImageView)
Set as background!
Just kidding... what you need is put your views inside a RelativeLayout. Something like will work:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:text="blah blah"/>
</RelativeLayout>
Notice the use of params like layout_alignParentLeft which are used to position the view where you want.
I agree with #Cristian's answer. but also,
If you need button's action listener you can add onClick method to your imageView without using button.
And also ImageButton. I hope this answer shows some path to solve your problem.
Worked for me with both ImageView and Button inside RelativeLayout:
<Button android:layout_centerInParent="true">
...