How can I make my image scrollable? [Android Platform] - android

I have an image that takes up a lot more space than the android screen. I want the image to be presented full size and the user can move in any direction. Like a map.
Any suggestions?

You can use a webview which gives this to you for free. I'm not sure why but when I tried
using the loadData method it didn't work, but using loadDataWithBaseURL with a null URL did.
With a webview your image can even be embedded in HTML. In the example below yourContent is simply a string.
E.g.
yourView.loadDataWithBaseURL(null, yourContent, "text/html", "UTF-8", null);

Here is a tutorial I saw that did what you are describing
http://www.anddev.org/scrolling_a_picture_horizontally_and_vertically-t3245.html

You can put your image in an ImageView and wrap it using a ScrollView and a HorizontalScrollView like below.
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/yourImage"/>
</ScrollView>
</HorizontalScrollView>
So you can scroll it horizontally and vertically like a map.

Try to put scroll into xml layout with your image

Related

Android Webview is scrolling to the top when click on link

I have a Webview loading static html content in my app.
the problem is, when I click on a link or an embed content (tweet, youtube video), the webview is scrolling back to the top.
It looks like a JS problem as mentioned here
I tried to use a NestedScrollView or some tricks with params like
android:focusableInTouchMode="true"
in a LinearLayout parent but nothing works
here's my xml :
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="#+id/article_webview"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.v4.widget.NestedScrollView>
it will be in a recycler view.
My question is :
is there a way to prevent this behavior in the webview settings or xml ?
Thanks !
I've been having the same problem. My WebView was inside a RecyclerView too.
When I added android:descendantFocusability="blocksDescendants" on my RecyclerView, the problem does not happen for me anymore.
<androidx.recyclerview.widget.RecyclerView
android:descendantFocusability="blocksDescendants"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
I've been having the same problem. My WebView was inside a
LinearLayout.
When I added android:descendantFocusability="blocksDescendants" on my LinearLayout.
Issue was fixed with this changes.

how to make android layout which is scrollable and zoomable?

I want to make a layout like shown in images below. it's like googlemap and you can zoom in/out with multi finger touch, and also scrolling in four way. is there any library supporting this layout?
zoomed out image:
[http://i57.tinypic.com/2hoz6rl.png][1]
zoomed in and scrolled:
[http://i58.tinypic.com/zxnqqb.png][2]
.....
third pic in the comments
Use ScrollView element in your xml
<ScrollView
android:id="#+id/someId"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<HorizontalScrollView
android:id="#+id/horizontalSomeId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true" >
`enter code here`
</HorizontalScrollView>
</ScrollView>
Use TouchImageView.
Refers this link.
How can I get zoom functionality for images?
From here you can download TouchImageView class or Library.
https://github.com/MikeOrtiz/TouchImageView
https://github.com/MikeOrtiz/TouchImageView/blob/master/src/com/ortiz/touch/TouchImageView.java
If its works for you then give me a Check mark for correct answer.

Best way to create a header and footer for webview in Android

I want to create news like activity that has title and date and some share and favorite buttons in the beginning at the top, the article text (and maybe some images and headers titles) is in html that I get from server, and at the end a list of related news!
I have to use WebView for the article html, but since I need the header and the main webview to scroll together, I may have to use them in the in wraping ScrollView, which, apparently is not the best option!
I have red these:
webview in scrollview and
Disable scrolling in webview
but I want to know what is the best way to implement this as of 2015! that can work with android 4.01+
Well, as it turns out, best way to do yet is to just put them in a scrollView !
It worked on my Samsung android 4.4, but I don't know about the rest !
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/news_activity_title_lay"
android:layout_width="match_parent"
android:layout_height="wrap_content">
//Some Widgets Here for header
</RelativeLayout>
<WebView
android:layout_below="#+id/news_activity_title_lay"
android:id="#+id/news_activity_web_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white">
</WebView>
<LinearLayout
android:id="#+id/news_activity_related_base_lay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="#+id/news_activity_web_view">
//Some Widgets Here foe footer
</LinearLayout>
</RelativeLayout>
funny thing, though is Android Studio is saying I should not do this ! :/

Android: problem scrolling my activity including a WebView

I included a WebView in my activity and load some Javascript in it which is then going to get data from an external website.
This works and displays fine but the problem is that my activity doesn't scroll when the WebView is done loading so I can't see the bottom of the WebView such as all the other Views I put below this. Any idea of how I should handle this?
Cheers.
Are you using scrollview in your layout? Try that and see if that helps.
Here is a link to the developer page
This works and displays fine but the problem is that my activity doesn't scroll when the WebView is done loading so I can't see the bottom of the WebView such as all the other Views I put below this.
You need to change your layout such that the "other Views I put below this" will be on the screen, and the WebView simply takes up the remaining space.
For example, here is a layout showing a WebView with a Button:
<?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"
>
<WebView android:id="#+id/webkit"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="1"
/>
<Button android:id="#+id/helpcast"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="View Helpcast"
/>
</LinearLayout>
Because the WebView is set up with a 0px height but a weight of 1, and because the Button specifies no weight, the WebView will fill all space left over after the Button is on-screen. The WebView content will scroll inside the WebView itself, if needed, based upon whatever Web page you load in there.

Scroll view doesn't resize when the content of child view changes

I have a WebView inside the ScrollView.
The content of WebView dyanamically changes when it displays different html page.
I have the following issue:
For example I have A.html, and B.html. The content of B.html is larger than A.html, so the page is longer.
When WebView load B.html, the ScrollView stretches its size to enable itself scroll for B.html, then if I go back to A.html, ScrollView doesn't resize itself. (The scroll area is exceed the content of A.html)
What I want to have, is dynamic change the scroll area of scroll view to fit the webview's content.
Try using android:fillViewport in scroll view..!!
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
After Orientation screen will resize, it works but bad in performance, not a very good solution
setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE );
setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_SENSOR );
This helped me:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>
That's not good idea to place WebView inside of ScrollView. WebView is smart enough to show scrollbars by itself.
Don't put a WebView inside of a ScrollView.

Categories

Resources